Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751796AbdH3QTB (ORCPT ); Wed, 30 Aug 2017 12:19:01 -0400 Received: from mail-sn1nam02on0050.outbound.protection.outlook.com ([104.47.36.50]:51342 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751415AbdH3QS6 (ORCPT ); Wed, 30 Aug 2017 12:18:58 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Cc: brijesh.singh@amd.com, 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 , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Arnd Bergmann , Tejun Heo , Christoph Lameter Subject: Re: [RFC Part1 PATCH v3 16/17] X86/KVM: Provide support to create Guest and HV shared per-CPU variables To: Borislav Petkov References: <20170724190757.11278-1-brijesh.singh@amd.com> <20170724190757.11278-17-brijesh.singh@amd.com> <20170829102258.gxk227js4yw47qi3@pd.tnic> From: Brijesh Singh Message-ID: <0810a732-9c77-a543-ffeb-7fd2d8f46266@amd.com> Date: Wed, 30 Aug 2017 11:18:42 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170829102258.gxk227js4yw47qi3@pd.tnic> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CY4PR04CA0059.namprd04.prod.outlook.com (10.171.243.152) To BY2PR12MB0145.namprd12.prod.outlook.com (10.162.82.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1487450d-e6e6-4ba9-5f6d-08d4efc2cd65 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:BY2PR12MB0145; X-Microsoft-Exchange-Diagnostics: 1;BY2PR12MB0145;3:4cPhqT8iX6GeJInugvtqUrAhAQVz1OHQz/vZOItoptK81qBS2v5QRLlBUI/hvi83bsVvXGzXam8m2Xa6nnuiTokvRuVSqcS/an8C4gQPt1GP8YuoeGLnd598Oo1ZzJ28uW/dlIEKZSryhZQBPcGjxFsxn1nY3CjA4nBdiKx0+gvatZUF7Xfnr2dX3kql6sUq8L0MNm3NEwFwr6ZTFAWnurwt9cRkpWNsXC6thtkVisiE9NjvXz/8I5SPA+xZBQNs;25:HaLUCccSh3VNRp1werv1UYaN+UN+z+6VjDjbkbt0zB/Bmxg9QfFtYIL1E0CeJwypt7tR+E5tzhDKZahkNxXnbYRQFZofeOyyFoT0j597bMQDgEspIjIgkD+w/ks0YEVQSjYcxIjznzzMnY2Idu7DUZvAKc/tBmlMnxH1rEmMtWFCMYiyCYeJCukcf3l3ld6J5+uoVD6XBeAS4S+81ZcbwhZPtz4+TUM/0aN/sO+S6pxkJh0plalVwl7d/Jonb5uZ3dWC0vL371fvsU8gXkWWD4phmUrErm2sKzStvRfp+Xb3HiseJFm7fPNgQcfxcYwN77S5VymifrhHLUKdcfdTzA==;31:NtNlq3cZQDbmr8xxFPUMn3eFIz7lLXHizd8xVZWHHC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BQO0c= X-Exchange-Antispam-Report-Test: UriScan:(58145275503218); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(20161123562025)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BY2PR12MB0145;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BY2PR12MB0145; X-Forefront-PRVS: 041517DFAB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(6049001)(39860400002)(24454002)(377454003)(199003)(189002)(97736004)(575784001)(86362001)(31696002)(6246003)(81156014)(8676002)(81166006)(4001350100001)(76176999)(54356999)(50986999)(6306002)(66066001)(189998001)(65806001)(65956001)(36756003)(230700001)(54906002)(3846002)(966005)(2906002)(53936002)(6116002)(8936002)(42186005)(47776003)(106356001)(105586002)(33646002)(7406005)(7736002)(305945005)(90366009)(101416001)(77096006)(23676002)(6486002)(31686004)(229853002)(68736007)(7416002)(5660300001)(65826007)(2950100002)(6666003)(6916009)(110136004)(83506001)(478600001)(53546010)(64126003)(50466002)(25786009)(4326008);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR12MB0145;H:[10.236.136.62];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCWTJQUjEyTUIwMTQ1OzIzOmZhUVBvcWwyNmFpQ216Z1ZhcWR3VS9QeHR3?= =?utf-8?B?N3RaUTNOQnVlR1A4Ym9wOE5PbFFJRURWdkU4L0I5Mitkcm9NS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G9BQkxTRkZxdG1KYXJab2dkazM2?= =?utf-8?B?c3g0WGJCZklYYzJYTlcrcjFkdnpxaWdZYjdOTjI5eUlsUXhjYytmODlGeEJJ?= =?utf-8?Q?w9t3g7?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR12MB0145;6:PYisNu2+VhQBBNDQFsyu+vcNjsPKQ5fK2lTK1loT0uFtLq52j19SJadb9SevGzsSeU+ixtbpGvfZL/EdRFgpAbviMCRI5nmAFCz6YWRR8cTgxTVZuUyjQds3qVremoOTt+AfvXID/PvUTT3Qw7QsDPa+A4N4S+tU4GlFjXtt8xRMdSc63Gu+OhdSzMhPOQ/LaHtARJczBRogX/+VlFmPMysZuVDMQ+cCA1OYDzDpCRXOSIyTW8pq6EQ7OY6JVuX06aheE+uG/PwMKRnt7/ifjHUsMLkrjtA7h9aJk3MeIl+5E0qcrxJOSeM1hy6gC6e7jDZz48T7nEto3M+/hSgorw==;5:EWyDRXvvo6bjleBGvOTdvLYfsCpqHE/qxTpMVTA2dtThKe1ZgHF8CHkcNtJH2+QvggWYh4NDemFBBnjeFvF5E+ga+7+5WMzh4nLkDed61nyyhKbBntgiiyE7pIhMq0A06bc4RwnQMEIu1xOTu2TFfA==;24:PZJXlLm47kQ6b80TTd0g0xLDuH1zmehXHGvbIm2ZXT1kb6I9f+o22DCFDnXvEU39WpzylWr/YgWBsHEGi9Zw0SK/hepjh7dK+920auYurGs=;7:hlu4RsFW7RYre2gCoV3gXkAqGWz/RWz8F7dJYG869ULIydrAPoLmdQH06cHdjI4KlbYzWoLAyZIVGKUAMoMW8FA53O5ZfE6TW0NIy0IMvcXcEsDoqDms7rv0eV3ewP12GkNxIBewzncpplybQsEkAeJ0Nd2/itzvUttNWwPOxVqQlXlLrXe1bL6ZtUvjBgzyq6B7XeFF5BHH9ymGF+LN5otEozDGUes1Aq1dGUCCGVo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BY2PR12MB0145;20:4JQNgQFBP53izenH7BpXYjHg8sf4Z6PJPcVj+QSEe2Sc1dG2NS11ohDYzGDia5VgIUkBuXTEnqksoLLJKlp7avEOQLnnCM3VFKL2dvpfJrTzIOwaSPh2AJLMAeTUcdQmRKf0NktB6+WAL3nEAr+0Q8iUtUQIcgAqhingCoGuup149CICmrP6U2SlUUO9707NuenNhq0U8PY0cEMKZqRptVYtKqd2/sPjeSBElF0si1iJIt+Vb55eR6mVP4fHrx8g X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2017 16:18:48.3811 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0145 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3680 Lines: 112 Hi Boris, On 08/29/2017 05:22 AM, Borislav Petkov wrote: [...] > On Mon, Jul 24, 2017 at 02:07:56PM -0500, Brijesh Singh wrote: >> Some KVM specific MSR's (steal-time, asyncpf, avic_eio) allocates per-CPU > > MSRs > >> variable at compile time and share its physical address with hypervisor. > > That sentence needs changing - the MSRs don't allocate - for them gets > allocated. > >> It presents a challege when SEV is active in guest OS, when SEV is active, >> the guest memory is encrypted with guest key hence hypervisor will not >> able to modify the guest memory. When SEV is active, we need to clear the >> encryption attribute (aka C-bit) of shared physical addresses so that both >> guest and hypervisor can access the data. > > This whole paragraph needs rewriting. > I will improve the commit message in next rev. [...] >> +/* NOTE: function is marked as __ref because it is used by __init functions */ > > No need for that comment. > > What should you look into is why do you need to call the early versions: > > " * producing a warning (of course, no warning does not mean code is > * correct, so optimally document why the __ref is needed and why it's OK)." > > And we do have the normal set_memory_decrypted() etc helpers so why > aren't we using those? > Since kvm_guest_init() is called early in the boot process hence we will not able to use set_memory_decrypted() function. IIRC, if we try calling set_memory_decrypted() early then we will hit a BUG_ON [1] -- mainly when it tries to flush the caches. [1] http://elixir.free-electrons.com/linux/latest/source/arch/x86/mm/pageattr.c#L167 > If you need to use the early ones too, then you probably need to > differentiate this in the callers by passing a "bool early", which calls > the proper flavor. > Sure I can rearrange code to make it more readable and use "bool early" parameter to differentiate it. >> +static int __ref kvm_map_hv_shared_decrypted(void) >> +{ >> + static int once, ret; >> + int cpu; >> + >> + if (once) >> + return ret; > > So this function gets called per-CPU but you need to do this ugly "once" > thing - i.e., global function called in a per-CPU context. > > Why can't you do that mapping only on the current CPU and then > when that function is called on the next CPU, it will do the same thing > on that next CPU? > Yes, it can be done but I remember running into issues during the CPU hot plug. The patch uses early_set_memory_decrypted() -- which calls kernel_physical_mapping_init() to split the large pages into smaller. IIRC, the API did not work after the system is successfully booted. After the system is booted we must use the set_memory_decrypted(). I was trying to avoid mixing early and no-early set_memory_decrypted() but if feedback is: use early_set_memory_decrypted() only if its required otherwise use set_memory_decrypted() then I can improve the logic in next rev. thanks [...] >> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h >> index da0be9a..52854cf 100644 >> --- a/include/asm-generic/vmlinux.lds.h >> +++ b/include/asm-generic/vmlinux.lds.h >> @@ -783,6 +783,9 @@ >> . = ALIGN(cacheline); \ >> *(.data..percpu) \ >> *(.data..percpu..shared_aligned) \ >> + . = ALIGN(PAGE_SIZE); \ >> + *(.data..percpu..hv_shared) \ >> + . = ALIGN(PAGE_SIZE); \ >> VMLINUX_SYMBOL(__per_cpu_end) = .; > > Yeah, no, you can't do that. That's adding this section unconditionally > on *every* arch. You need to do some ifdeffery like it is done at the > beginning of that file and have this only on the arch which supports SEV. > Will do . thanks -Brijesh