Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2278575rwb; Thu, 17 Nov 2022 08:41:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf7wNDdvBTouZbhR7/Rmi3mFm9kDsEyjRrQRRDVfbDywFA5vXopR+DtQy9HHhdiLfrg447Mw X-Received: by 2002:aa7:cb0d:0:b0:45a:2d7c:f3a0 with SMTP id s13-20020aa7cb0d000000b0045a2d7cf3a0mr2876647edt.98.1668703290227; Thu, 17 Nov 2022 08:41:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668703290; cv=none; d=google.com; s=arc-20160816; b=i6mO2fZ4Pan3ZFpdk/Gf/+V3KO96IwB3210k3G8d2Vm5jULXE6sW4EEhnjnSELxWtK qS7t35fs0nCpzff3BxksojKZaIKcOOKY+rl3wzkORn9En74oYKJINolnI5htsxFItED3 IXrBuSgFKspRxq1nXEgmPUtYUgRq1lMa7R0gtWFlJ1F5ZBJB1q6J968KkptkYnqxVD1F brpoPVydVNMwWpGcXnnyi98Xxj7H1OdsckrJa3ugg9gPAgRnRidTeyLtDFRW1s56Zo5t SFhTFw+mSQs9DMykDrw9EnEGoiYOR4Rm5q8XQXepQE7CUwO6j8I+VZxgFtVtnRvQCEN8 Sung== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Y9CVDfHX+ht3pe9PoZgShRnEuMK3hhYjUL+PhteMYLs=; b=LbMZwpC/8M4BUWcxoy4q30vJP7/v8TA8l3iu2jc0qIlfX/75/322UmTzYwkAgUo4Rz YuD20454nRqlJpqQlL3nZ+1ujhcX8HvJKB1a/u1sSgOlbTdH4VTWu1weW8wXxB4Xge0r 84l6on2iCASvt6L4l2s40uxeaJP/SDigKELjSPvlxhYaZ8TSSS7PB8+BNKhYAIuJdIVw Rv6DjMeC16MucqrimWiDu2JJ4ZkyM/zUzKwGdCpsyAbeCsO2x9qdVhQ0ZQpI8PeZzDU0 RSN5DXeHder+LXMaixlgzY/E3PXOAlT8p2vto4Ao+U3VhkazUaijDXpNni8Yb0RejNLa pVaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="f/q9dbYV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa17-20020a170907869100b0078239e3f846si1034924ejc.1.2022.11.17.08.41.07; Thu, 17 Nov 2022 08:41:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="f/q9dbYV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240671AbiKQQeu (ORCPT + 93 others); Thu, 17 Nov 2022 11:34:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233886AbiKQQeW (ORCPT ); Thu, 17 Nov 2022 11:34:22 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB2E75BD46 for ; Thu, 17 Nov 2022 08:32:04 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id jn7so244060plb.13 for ; Thu, 17 Nov 2022 08:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Y9CVDfHX+ht3pe9PoZgShRnEuMK3hhYjUL+PhteMYLs=; b=f/q9dbYV9KIClED5x6XtnNH9OBcIoYvpVlY3B8f7i0gA+unFTY0qNc4wR8aIGoXTrT rtw+8cfJhy5Qza7fbjpkC+luhVdAYjWJuUet1bg8OVb/V98lJ1qBftWPC1VPNWyZtibz 6sRgxWBE2yoShXjcUM9Ugr7rntaliexeg8YjtupMP2ZG1G3AGrEQzZCKaRlakNdoR9HJ ICnuOTPJVhQur77Ec83ZeeoLqeaQWIt11K3f5W91Npt26VtuNXMms15xGcz2GRSYgksD LaZ62GhBy3dwvAxldgN57cZKNCROlQJp8qt9pfYixbMd+q4BfRhxdsoercr8tXDSLUy8 8Sfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Y9CVDfHX+ht3pe9PoZgShRnEuMK3hhYjUL+PhteMYLs=; b=ofTz3ggCDQGi24520o+4aiXHR1XPmJm2HyjHVDpWqHJsz/YWB3Kl4UbszkPRuSv/RD dxSiGSz78G8EjUQVqGHbQtBubd9VAAislVgSdJaayd4U7EBczT3HUoaXDYLIDq2h2lPj fcQ3B3wq4LyXW6tm1j6xPC6w6mI4x8E+uenMCboOWUJlTN7QUE9+5GQsBGEH+QtWyBzT WW4UCQbSrq6W6RrdwXbdFyzjTjswn1WYzlFIBNDttZayGQ1kbEVF5pTXXROD2zH/9giY 3+kpcKc703VeUAKThX+iQhLiqeBrrOdhGwPrX9oINeGTDkuxcPehdbO/KpYrFj46V1ka 3IgA== X-Gm-Message-State: ANoB5plIV0zSEYRkOaeQlCvbwZhTlFCIxP4ogael3so97JtcQTQFiT5v CNgx8D1B9fBp22P9wlcXjMxFeQ== X-Received: by 2002:a17:90b:710:b0:20a:2547:907 with SMTP id s16-20020a17090b071000b0020a25470907mr9733486pjz.37.1668702724236; Thu, 17 Nov 2022 08:32:04 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id u15-20020a170902e80f00b001869581f7ecsm1628090plg.116.2022.11.17.08.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 08:32:03 -0800 (PST) Date: Thu, 17 Nov 2022 16:32:00 +0000 From: Sean Christopherson To: Wei Liu Cc: Michael Kelley , hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com, luto@kernel.org, peterz@infradead.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lpieralisi@kernel.org, robh@kernel.org, kw@linux.com, bhelgaas@google.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, Tianyu.Lan@microsoft.com, kirill.shutemov@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, dan.j.williams@intel.com, jane.chu@oracle.com, tony.luck@intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev Subject: Re: [Patch v3 13/14] PCI: hv: Add hypercalls to read/write MMIO space Message-ID: References: <1668624097-14884-1-git-send-email-mikelley@microsoft.com> <1668624097-14884-14-git-send-email-mikelley@microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 17, 2022, Wei Liu wrote: > On Wed, Nov 16, 2022 at 10:41:36AM -0800, Michael Kelley wrote: > [...] > > > > +static void hv_pci_read_mmio(struct device *dev, phys_addr_t gpa, int size, u32 *val) > > +{ > > + struct hv_mmio_read_input *in; > > + struct hv_mmio_read_output *out; > > + u64 ret; > > + > > + /* > > + * Must be called with interrupts disabled so it is safe > > + * to use the per-cpu input argument page. Use it for > > + * both input and output. > > + */ There's no need to require interrupts to be disabled to safely use a per-cpu variable, simply disabling preemption also provides the necessary protection. And this_cpu_ptr() will complain with CONFIG_DEBUG_PREEMPT=y if preemption isn't disabled. IIUC, based on the existing code, what is really be guarded against is an IRQ arriving and initiating a different hypercall from IRQ context, and thus corrupting the page from this function's perspective. > Perhaps adding something along this line? > > WARN_ON(!irqs_disabled()); Given that every use of hyperv_pcpu_input_arg except hv_common_cpu_init() disables IRQs, what about adding a helper to retrieve the pointer and assert that IRQs are disabled? I.e. add the sanity for all usage, not just this one-off case. And since CPUHP_AP_ONLINE_DYN => hv_common_cpu_init() runs after scheduling is activated by CPUHP_AP_SCHED_WAIT_EMPTY, I believe that hv_common_cpu_init() is theoretically broken. Maybe someone can look at that when fixing he KVM vs. Hyper-V issue? https://lore.kernel.org/linux-hyperv/878rkqr7ku.fsf@ovpn-192-136.brq.redhat.com https://lore.kernel.org/all/87sfikmuop.fsf@redhat.com