From: tip-bot for Andy Lutomirski <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com,
quentin.casasnovas@oracle.com, fenghua.yu@intel.com,
mingo@kernel.org, oleg@redhat.com, torvalds@linux-foundation.org,
tglx@linutronix.de, hpa@zytor.com, bp@alien8.de,
luto@amacapital.net, keescook@chromium.org, peterz@infradead.org,
luto@kernel.org
Subject: [tip:x86/asm] x86/vdso: Use .fault for the vDSO text mapping
Date: Tue, 12 Jan 2016 04:03:45 -0800 [thread overview]
Message-ID: <tip-05ef76b20fc4297b0d3f8a956f1c809a8a1b3f1d@git.kernel.org> (raw)
In-Reply-To: <f886954c186bafd74e1b967c8931d852ae199aa2.1451446564.git.luto@kernel.org>
Commit-ID: 05ef76b20fc4297b0d3f8a956f1c809a8a1b3f1d
Gitweb: http://git.kernel.org/tip/05ef76b20fc4297b0d3f8a956f1c809a8a1b3f1d
Author: Andy Lutomirski <luto@kernel.org>
AuthorDate: Tue, 29 Dec 2015 20:12:22 -0800
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 12 Jan 2016 11:59:34 +0100
x86/vdso: Use .fault for the vDSO text mapping
The old scheme for mapping the vDSO text is rather complicated.
vdso2c generates a struct vm_special_mapping and a blank .pages
array of the correct size for each vdso image. Init code in
vdso/vma.c populates the .pages array for each vDSO image, and
the mapping code selects the appropriate struct
vm_special_mapping.
With .fault, we can use a less roundabout approach: vdso_fault()
just returns the appropriate page for the selected vDSO image.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/f886954c186bafd74e1b967c8931d852ae199aa2.1451446564.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/entry/vdso/vdso2c.h | 7 -------
arch/x86/entry/vdso/vma.c | 26 +++++++++++++++++++-------
arch/x86/include/asm/vdso.h | 3 ---
3 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/arch/x86/entry/vdso/vdso2c.h b/arch/x86/entry/vdso/vdso2c.h
index 0224987..abe961c 100644
--- a/arch/x86/entry/vdso/vdso2c.h
+++ b/arch/x86/entry/vdso/vdso2c.h
@@ -150,16 +150,9 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
}
fprintf(outfile, "\n};\n\n");
- fprintf(outfile, "static struct page *pages[%lu];\n\n",
- mapping_size / 4096);
-
fprintf(outfile, "const struct vdso_image %s = {\n", name);
fprintf(outfile, "\t.data = raw_data,\n");
fprintf(outfile, "\t.size = %lu,\n", mapping_size);
- fprintf(outfile, "\t.text_mapping = {\n");
- fprintf(outfile, "\t\t.name = \"[vdso]\",\n");
- fprintf(outfile, "\t\t.pages = pages,\n");
- fprintf(outfile, "\t},\n");
if (alt_sec) {
fprintf(outfile, "\t.alt = %lu,\n",
(unsigned long)GET_LE(&alt_sec->sh_offset));
diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 80b0210..eb50d7c 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -27,13 +27,7 @@ unsigned int __read_mostly vdso64_enabled = 1;
void __init init_vdso_image(const struct vdso_image *image)
{
- int i;
- int npages = (image->size) / PAGE_SIZE;
-
BUG_ON(image->size % PAGE_SIZE != 0);
- for (i = 0; i < npages; i++)
- image->text_mapping.pages[i] =
- virt_to_page(image->data + i*PAGE_SIZE);
apply_alternatives((struct alt_instr *)(image->data + image->alt),
(struct alt_instr *)(image->data + image->alt +
@@ -90,6 +84,24 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
#endif
}
+static int vdso_fault(const struct vm_special_mapping *sm,
+ struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+ const struct vdso_image *image = vma->vm_mm->context.vdso_image;
+
+ if (!image || (vmf->pgoff << PAGE_SHIFT) >= image->size)
+ return VM_FAULT_SIGBUS;
+
+ vmf->page = virt_to_page(image->data + (vmf->pgoff << PAGE_SHIFT));
+ get_page(vmf->page);
+ return 0;
+}
+
+static const struct vm_special_mapping text_mapping = {
+ .name = "[vdso]",
+ .fault = vdso_fault,
+};
+
static int map_vdso(const struct vdso_image *image, bool calculate_addr)
{
struct mm_struct *mm = current->mm;
@@ -131,7 +143,7 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
image->size,
VM_READ|VM_EXEC|
VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
- &image->text_mapping);
+ &text_mapping);
if (IS_ERR(vma)) {
ret = PTR_ERR(vma);
diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
index deabaf9..43dc55b 100644
--- a/arch/x86/include/asm/vdso.h
+++ b/arch/x86/include/asm/vdso.h
@@ -13,9 +13,6 @@ struct vdso_image {
void *data;
unsigned long size; /* Always a multiple of PAGE_SIZE */
- /* text_mapping.pages is big enough for data/size page pointers */
- struct vm_special_mapping text_mapping;
-
unsigned long alt, alt_len;
long sym_vvar_start; /* Negative offset to the vvar area */
next prev parent reply other threads:[~2016-01-12 12:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-30 4:12 [PATCH v3 0/7] mm, x86/vdso: Special IO mapping improvements Andy Lutomirski
2015-12-30 4:12 ` [PATCH v3 1/7] x86/vsdo: Fix build on PARAVIRT_CLOCK=y, KVM_GUEST=n Andy Lutomirski
2016-01-05 19:21 ` Borislav Petkov
2016-01-06 9:54 ` [tip:x86/asm] x86/vsdo: Fix build on PARAVIRT_CLOCK=y, KVM_GUEST= n tip-bot for Andy Lutomirski
2015-12-30 4:12 ` [PATCH v3 2/7] mm: Add a vm_special_mapping .fault method Andy Lutomirski
2016-01-12 12:02 ` [tip:x86/asm] mm: Add a vm_special_mapping.fault() method tip-bot for Andy Lutomirski
2015-12-30 4:12 ` [PATCH v3 3/7] mm: Add vm_insert_pfn_prot Andy Lutomirski
2016-01-12 12:02 ` [tip:x86/asm] mm: Add vm_insert_pfn_prot() tip-bot for Andy Lutomirski
2015-12-30 4:12 ` [PATCH v3 4/7] x86/vdso: Track each mm's loaded vdso image as well as its base Andy Lutomirski
2016-01-12 12:03 ` [tip:x86/asm] x86/vdso: Track each mm' s loaded vDSO " tip-bot for Andy Lutomirski
2015-12-30 4:12 ` [PATCH v3 5/7] x86,vdso: Use .fault for the vdso text mapping Andy Lutomirski
2016-01-12 12:03 ` tip-bot for Andy Lutomirski [this message]
2015-12-30 4:12 ` [PATCH v3 6/7] x86,vdso: Use .fault instead of remap_pfn_range for the vvar mapping Andy Lutomirski
2016-01-12 12:04 ` [tip:x86/asm] x86/vdso: Use ->fault() instead of remap_pfn_range( ) " tip-bot for Andy Lutomirski
2015-12-30 4:12 ` [PATCH v3 7/7] x86/vdso: Disallow vvar access to vclock IO for never-used vclocks Andy Lutomirski
2016-01-12 12:04 ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2016-01-05 0:02 ` [PATCH v3 0/7] mm, x86/vdso: Special IO mapping improvements Kees Cook
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=tip-05ef76b20fc4297b0d3f8a956f1c809a8a1b3f1d@git.kernel.org \
--to=tipbot@zytor.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=quentin.casasnovas@oracle.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).