linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Heiko Carstens <hca@linux.ibm.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>,
	David Hildenbrand <david@redhat.com>,
	g@linux.dev, Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	martin.lau@kernel.org, linux-mm@kvack.org,
	linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	rppt@kernel.org, yosryahmed@google.com,
	Yi Lai <yi1.lai@intel.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Ilya Leoshkevich <iii@linux.ibm.com>
Subject: Re: [PATCH v2 bpf] lib/buildid: handle memfd_secret() files in build_id_parse()
Date: Thu, 17 Oct 2024 19:54:31 +0200	[thread overview]
Message-ID: <20241017175431.6183-A-hca@linux.ibm.com> (raw)
In-Reply-To: <CAEf4BzZzctRsxQ7n42AJrm8XTyxhN+-ceE7Oz5jokz4ALqDekQ@mail.gmail.com>

On Thu, Oct 17, 2024 at 10:35:27AM -0700, Andrii Nakryiko wrote:
> On Thu, Oct 17, 2024 at 9:35 AM Shakeel Butt <shakeel.butt@linux.dev> wrote:
> > On Thu, Oct 17, 2024 at 11:18:34AM GMT, David Hildenbrand wrote:
> > > As replied elsewhere, can't we take a look at the mapping?
> > >
> > > We do the same thing in gup_fast_folio_allowed() where we check
> > > secretmem_mapping().
> >
> > Responded on the v1 but I think we can go with v1 of this work as
> > whoever will be working on unmapping folios from direct map will need to
> > fix gup_fast_folio_allowed(), they can fix this code as well. Also it
> > seems like some arch don't have kernel_page_present() and builds are
> > failing.
> >
> 
> Yeah, we are lucky that BPF CI tested s390x and caught this issue.
> 
> > Andrii, let's move forward with the v1 patch.
> 
> Let me post v3 based on v1 (checking for secretmem_mapping()), but
> I'll change return code to -EFAULT, so in the future this can be
> rolled into generic error handling code path with no change in error
> code.

Ok, I've seen that you don't need kernel_page_present() anymore, just
after I implemented it for s390. I guess I'll send the patch below
(with a different commit message) upstream anyway, just in case
somebody else comes up with a similar use case.

>From b625edc35de64293b728b030c62f7aaa65c8627e Mon Sep 17 00:00:00 2001
From: Heiko Carstens <hca@linux.ibm.com>
Date: Thu, 17 Oct 2024 19:41:07 +0200
Subject: [PATCH] s390/pageattr: Implement missing kernel_page_present()

kernel_page_present() was intentionally not implemented when adding
ARCH_HAS_SET_DIRECT_MAP support, since it was only used for suspend/resume
which is not supported anymore on s390.

However a new bpf use case now leads to a compile error specific to
s390. Implement kernel_page_present() to fix this.

Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Closes: https://lore.kernel.org/all/045de961-ac69-40cc-b141-ab70ec9377ec@iogearbox.net
Fixes: 0490d6d7ba0a ("s390/mm: enable ARCH_HAS_SET_DIRECT_MAP")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/include/asm/set_memory.h |  1 +
 arch/s390/mm/pageattr.c            | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/arch/s390/include/asm/set_memory.h b/arch/s390/include/asm/set_memory.h
index 06fbabe2f66c..cb4cc0f59012 100644
--- a/arch/s390/include/asm/set_memory.h
+++ b/arch/s390/include/asm/set_memory.h
@@ -62,5 +62,6 @@ __SET_MEMORY_FUNC(set_memory_4k, SET_MEMORY_4K)
 
 int set_direct_map_invalid_noflush(struct page *page);
 int set_direct_map_default_noflush(struct page *page);
+bool kernel_page_present(struct page *page);
 
 #endif
diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c
index 5f805ad42d4c..aec9eb16b6f7 100644
--- a/arch/s390/mm/pageattr.c
+++ b/arch/s390/mm/pageattr.c
@@ -406,6 +406,21 @@ int set_direct_map_default_noflush(struct page *page)
 	return __set_memory((unsigned long)page_to_virt(page), 1, SET_MEMORY_DEF);
 }
 
+bool kernel_page_present(struct page *page)
+{
+	unsigned long addr;
+	unsigned int cc;
+
+	addr = (unsigned long)page_address(page);
+	asm volatile(
+		"	lra	%[addr],0(%[addr])\n"
+		"	ipm	%[cc]\n"
+		: [cc] "=d" (cc), [addr] "+a" (addr)
+		:
+		: "cc");
+	return (cc >> 28) == 0;
+}
+
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE)
 
 static void ipte_range(pte_t *pte, unsigned long address, int nr)
-- 
2.45.2



  reply	other threads:[~2024-12-05 15:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16 22:16 Andrii Nakryiko
2024-10-16 22:21 ` Yosry Ahmed
2024-10-16 23:57 ` Shakeel Butt
2024-10-17  8:59 ` Daniel Borkmann
2024-10-17  9:18 ` David Hildenbrand
2024-10-17 16:35   ` Shakeel Butt
2024-10-17 17:35     ` Andrii Nakryiko
2024-10-17 17:54       ` Heiko Carstens [this message]
2024-10-17 18:23         ` Andrii Nakryiko
2024-10-17 11:07 ` kernel test robot
2024-10-17 11:59 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241017175431.6183-A-hca@linux.ibm.com \
    --to=hca@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=david@redhat.com \
    --cc=g@linux.dev \
    --cc=gor@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=yi1.lai@intel.com \
    --cc=yosryahmed@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox