Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751132AbdHBEDt (ORCPT ); Wed, 2 Aug 2017 00:03:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:57741 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751050AbdHBEDr (ORCPT ); Wed, 2 Aug 2017 00:03:47 -0400 Date: Wed, 2 Aug 2017 06:02:56 +0200 From: Borislav Petkov To: Brijesh Singh Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-efi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andy Lutomirski , Tony Luck , Piotr Luc , Tom Lendacky , Fenghua Yu , Lu Baolu , Reza Arbab , David Howells , Matt Fleming , "Kirill A . Shutemov" , Laura Abbott , Ard Biesheuvel , Andrew Morton , Eric Biederman , Benjamin Herrenschmidt , Paul Mackerras , Konrad Rzeszutek Wilk , Jonathan Corbet , Dave Airlie , Kees Cook , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Arnd Bergmann , Tejun Heo , Christoph Lameter Subject: Re: [RFC Part1 PATCH v3 11/17] x86/mm, resource: Use PAGE_KERNEL protection for ioremap of memory pages Message-ID: <20170802040255.GA4336@nazgul.tnic> References: <20170724190757.11278-1-brijesh.singh@amd.com> <20170724190757.11278-12-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170724190757.11278-12-brijesh.singh@amd.com> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2544 Lines: 73 On Mon, Jul 24, 2017 at 02:07:51PM -0500, Brijesh Singh wrote: > From: Tom Lendacky > > In order for memory pages to be properly mapped when SEV is active, we > need to use the PAGE_KERNEL protection attribute as the base protection. > This will insure that memory mapping of, e.g. ACPI tables, receives the > proper mapping attributes. > > Signed-off-by: Tom Lendacky > Signed-off-by: Brijesh Singh > --- > arch/x86/mm/ioremap.c | 28 ++++++++++++++++++++++++++++ > include/linux/ioport.h | 3 +++ > kernel/resource.c | 17 +++++++++++++++++ > 3 files changed, 48 insertions(+) > > diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c > index c0be7cf..7b27332 100644 > --- a/arch/x86/mm/ioremap.c > +++ b/arch/x86/mm/ioremap.c > @@ -69,6 +69,26 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages, > return 0; > } > > +static int __ioremap_res_desc_other(struct resource *res, void *arg) > +{ > + return (res->desc != IORES_DESC_NONE); > +} > + > +/* > + * This function returns true if the target memory is marked as > + * IORESOURCE_MEM and IORESOURCE_BUSY and described as other than > + * IORES_DESC_NONE (e.g. IORES_DESC_ACPI_TABLES). > + */ > +static bool __ioremap_check_if_mem(resource_size_t addr, unsigned long size) > +{ > + u64 start, end; > + > + start = (u64)addr; > + end = start + size - 1; > + > + return (walk_mem_res(start, end, NULL, __ioremap_res_desc_other) == 1); > +} > + > /* > * Remap an arbitrary physical address space into the kernel virtual > * address space. It transparently creates kernel huge I/O mapping when > @@ -146,7 +166,15 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr, > pcm = new_pcm; > } > > + /* > + * If the page being mapped is in memory and SEV is active then > + * make sure the memory encryption attribute is enabled in the > + * resulting mapping. > + */ > prot = PAGE_KERNEL_IO; > + if (sev_active() && __ioremap_check_if_mem(phys_addr, size)) > + prot = pgprot_encrypted(prot); Hmm, so this function already does walk_system_ram_range() a bit earlier and now on SEV systems we're going to do it again. Can we make walk_system_ram_range() return a distinct value for SEV systems and act accordingly in __ioremap_caller() instead of repeating the operation? It looks to me like we could... -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --