Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2307526ybt; Tue, 16 Jun 2020 02:36:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8Hfk/5qZAIxjsXjgS8bXrCnB4jX81e9yrp50Jq9GLg8CLX+40FS19w8hB2jdbHWxJIhme X-Received: by 2002:a17:906:ae88:: with SMTP id md8mr1999276ejb.347.1592300167554; Tue, 16 Jun 2020 02:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592300167; cv=none; d=google.com; s=arc-20160816; b=TCgXff1FK1HzPQSVXMOtyVF52OmcRtglbJnth3Da2oT5Q6Wn9QsVBGBmKraKEa/1Mo WAIRI6oDrRWuBoeiTdWsJWK5o1kGon1/sJTHEwL5QQ1sk03DZG4Qn9iPy2Hg7BgcmkwF JKX7KoZ1FTx1WFyWH7GgOAFIsfDBT0hiaFeq2OVCtPvKEWJnFwk438V8JJSfiv84Zpoy 71n0yyfFoA8KX2oTmJ7Z0TL4tttSXn4yfdfipZGBZtfQgxIhXcw4uX+1Vje7NyurzPYC ZQLeORQSqApxjZly2lxiGOmjHRMnW0JfxVfZPN3qkTb7TM6+LOl6jwj38lI+l9hOVDG2 mU/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=sykhPhmnvQ79+/OKeTxe5mzyxO6EV4IFYn9e8BVPmjk=; b=QYks+j9lc35AbGZELltVI7M7zaLo+63ZE+fxm+uM3mPRrabWjNOGaEBIw7qyG6mbhc ahrSSJMqBOsMmVU0z/ezzEAakbzv6jHffBvoxMc8L9pl7pEgRvfr5UK0moz008eI+mdw XQa/Ph1vEHpFYPRGCeZxC4He5dMZOuSi54j8jGZv7UOnpK5OBjPQ8dYz87oUjInG6Noh zTGvEymC0M31e5p2s40hqv33saWv9LCJTQ65734zwvBsXRlkTOunGPFbKZQM8GcjTx37 HEd/JB5q4sSFDMlGJmEHScX8RJFRLt2qlwAxXfjarNTGrFj1g+JHWxuY4XanlWo0GXWg yHwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz9si9902167ejc.664.2020.06.16.02.35.44; Tue, 16 Jun 2020 02:36:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727935AbgFPJdp (ORCPT + 99 others); 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.