From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3E36C433DF for ; Tue, 16 Jun 2020 09:33:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9ADD320707 for ; Tue, 16 Jun 2020 09:33:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727990AbgFPJdp (ORCPT ); Tue, 16 Jun 2020 05:33:45 -0400 Received: from verein.lst.de ([213.95.11.211]:37209 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbgFPJdp (ORCPT ); Tue, 16 Jun 2020 05:33:45 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id BAFB068AFE; Tue, 16 Jun 2020 11:33:41 +0200 (CEST) Date: Tue, 16 Jun 2020 11:33:41 +0200 From: Christoph Hellwig To: Vitaly Kuznetsov Cc: Dexuan Cui , Christoph Hellwig , Stephen Hemminger , Andy Lutomirski , Peter Zijlstra , Andy Lutomirski , Michael Kelley , Ju-Hyoung Lee , "x86@kernel.org" , "linux-hyperv@vger.kernel.org" , "linux-kernel@vger.kernel.org" , KY Srinivasan Subject: Re: hv_hypercall_pg page permissios Message-ID: <20200616093341.GA26400@lst.de> References: <20200407073830.GA29279@lst.de> <87y2ooiv5k.fsf@vitty.brq.redhat.com> <87blljicjm.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87blljicjm.fsf@vitty.brq.redhat.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 16, 2020 at 11:29:33AM +0200, Vitaly Kuznetsov wrote: > it seems we need something like PAGE_KERNEL_READONLY_EXEC but we don't > seem to have one on x86. Hypercall page is special in a way that the > guest doesn't need to write there at all. vmalloc_exec() seems to have > only one other user on x86: module_alloc() and it has other needs. module_alloc actually is a weak function and overriden on x86 (and many other architectures) , so it isn't used either (did I mention that I hate weak functions?) > On > ARM, alloc_insn_page() does the following: > > arch/arm64/kernel/probes/kprobes.c: page = vmalloc_exec(PAGE_SIZE); > arch/arm64/kernel/probes/kprobes.c- if (page) { > arch/arm64/kernel/probes/kprobes.c- set_memory_ro((unsigned long)page, 1); > arch/arm64/kernel/probes/kprobes.c- set_vm_flush_reset_perms(page); > arch/arm64/kernel/probes/kprobes.c- } > > What if we do the same? (almost untested): > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > index e2137070386a..31aadfea589b 100644 > --- a/arch/x86/hyperv/hv_init.c > +++ b/arch/x86/hyperv/hv_init.c > @@ -23,6 +23,7 @@ > #include > #include > #include > +#include > #include > > void *hv_hypercall_pg; > @@ -383,6 +384,8 @@ void __init hyperv_init(void) > wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0); > goto remove_cpuhp_state; > } > + set_memory_ro((unsigned long)hv_hypercall_pg, 1); > + set_vm_flush_reset_perms(hv_hypercall_pg); This should work and might be the best for 5.8, but I think we need to sort this whole mess out for real.