Message ID | 1680564122-30819-1-git-send-email-nunodasneves@linux.microsoft.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2662414vqo; Mon, 3 Apr 2023 17:05:57 -0700 (PDT) X-Google-Smtp-Source: AKy350ZrBDj+onGoqAwUlduf1OwqDThfeN/pVDlbKVOBfVRf0whPiw8FaXkcNjx/nHRhZObueNYP X-Received: by 2002:a05:6a20:65a1:b0:cc:a8d7:ad7e with SMTP id p33-20020a056a2065a100b000cca8d7ad7emr386349pzh.60.1680566757713; Mon, 03 Apr 2023 17:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680566757; cv=none; d=google.com; s=arc-20160816; b=QAtCTPjhgkmmV/gWqEbqxJpcHXhKpP1GkQkPlabIZDddTzmgwzYnLmG0a8dR2ZT8T2 gMAtsjoJflZernkfKkFfpTdhDoeSLep6cBxMrRvbVv7kZee6O4ewD4hmv9FP+vG0msJ1 wz1iJ6vNZwk0QMgeTSh/m3S2RiGqQHDzREDcPpTgovYyZAHcRNG6CcnNo6VgXVb1W0g4 nUtn1YxIVr2nKYh4Eu/Y6BJK+XhuKfflb7k0ElMWt82RUwRaKWPUctZPm8AVLheUaQkv WIZRgFHiPhsCF8GOZao5Piu7C/aPBp/4I7tAlBEPKHn/qjFMQB+yLgatj4HcUkeyHqps diaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=MC+jadVc7FZbGi+PwmB9b0t3If3HuxEogBotcxti98I=; b=Pa7wo2WxVWjBpxF+Zi4+VuwIfh7IThBosQbW1zG2uyaYa+iUMGCD0cz3+VsvW0SqsN uRJhaOmVz7bx8efFnDS0OMSSrIFgGg9ZHwNKp+djoy1MpGwn+/grPKkPHDOwws1Syi20 sSe40D23Bq3eNJGLeK0lVxAAjgvWEL62RrJTMcN+UHQTld+CCBrGt88w6SNmkzM2gK2t 3lM41EOHbOQJ/p1iiiHtM8+HnaI8pIngyB7mJ24Tzmve1HP6uwcKxwudBZrJU5apDS/n RfNo4Z9T3pblOIj1Ecucpt4bqgHGgTMljWm0vimFoIXYr46PA20mDFf3eAv+M0fW2JOt TAsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=X46iBUYG; 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=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t193-20020a635fca000000b00508b12a837bsi8912239pgb.156.2023.04.03.17.05.45; Mon, 03 Apr 2023 17:05:57 -0700 (PDT) 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=@linux.microsoft.com header.s=default header.b=X46iBUYG; 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=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233870AbjDCXWU (ORCPT <rfc822;zwp10758@gmail.com> + 99 others); Mon, 3 Apr 2023 19:22:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233284AbjDCXWT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 3 Apr 2023 19:22:19 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E5889211F; Mon, 3 Apr 2023 16:22:18 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 6A784210CBF2; Mon, 3 Apr 2023 16:22:18 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6A784210CBF2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680564138; bh=MC+jadVc7FZbGi+PwmB9b0t3If3HuxEogBotcxti98I=; h=From:To:Cc:Subject:Date:From; b=X46iBUYGR8gEtSk2jXJFF/MeQphJna/uVGxpdfPl5XYIAR4pTYTc84kVOd+hdx3XR nS2se5fOGKUeQuy4BHNYxTtIXjN4TIfXpA/jyd1U/u9dJQ665wqHZq33vv+0PfPoc0 jftKOfk+FSmfnZl7TZEafLjzQ91RTAy09UYjrisU= From: Nuno Das Neves <nunodasneves@linux.microsoft.com> To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Cc: mikelley@microsoft.com, kys@microsoft.com, wei.liu@kernel.org, haiyangz@microsoft.com, decui@microsoft.com Subject: [PATCH] Drivers: hv: Do not free synic pages when they were not allocated Date: Mon, 3 Apr 2023 16:22:02 -0700 Message-Id: <1680564122-30819-1-git-send-email-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-17.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762201968363722881?= X-GMAIL-MSGID: =?utf-8?q?1762201968363722881?= |
Series |
Drivers: hv: Do not free synic pages when they were not allocated
|
|
Commit Message
Nuno Das Neves
April 3, 2023, 11:22 p.m. UTC
In case of root partition or snp, the synic pages are allocated by the
hypervisor instead of the kernel, so they should not be freed.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
drivers/hv/hv.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
Reviewed-by: Jinank Jain <jinankjain@linux.microsoft.com> On 4/4/2023 4:52 AM, Nuno Das Neves wrote: > In case of root partition or snp, the synic pages are allocated by the > hypervisor instead of the kernel, so they should not be freed. > > Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com> > --- > drivers/hv/hv.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c > index c7f7652932ca..a10cf642c9ad 100644 > --- a/drivers/hv/hv.c > +++ b/drivers/hv/hv.c > @@ -193,8 +193,10 @@ void hv_synic_free(void) > struct hv_per_cpu_context *hv_cpu > = per_cpu_ptr(hv_context.cpu_context, cpu); > > - free_page((unsigned long)hv_cpu->synic_event_page); > - free_page((unsigned long)hv_cpu->synic_message_page); > + if (!hv_isolation_type_snp() && !hv_root_partition) { > + free_page((unsigned long)hv_cpu->synic_event_page); > + free_page((unsigned long)hv_cpu->synic_message_page); > + } > free_page((unsigned long)hv_cpu->post_msg_page); > } >
From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Monday, April 3, 2023 4:22 PM > > In case of root partition or snp, the synic pages are allocated by the > hypervisor instead of the kernel, so they should not be freed. This patch doesn't hurt anything, but is it really needed? In the SNP Isolation or root partition case, after hv_synic_alloc() has run, the synic_event_page and synic_message_page pointers are NULL. Then when hv_synic_enable_regs() is run by a particular CPU, that CPU maps the pages and the pointers are non-NULL. But the corresponding hv_synic_disable_regs() sets the pointers back to NULL, so hv_synic_free() will already skip those pages. Is there ever a case where hv_synic_free() would run after a CPU has done hv_synic_enable_regs(), but not hv_synic_disable_regs()? If that were the case, it seems like we would have other problems, such as missing calls to iounmap(). Michael > > Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com> > --- > drivers/hv/hv.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c > index c7f7652932ca..a10cf642c9ad 100644 > --- a/drivers/hv/hv.c > +++ b/drivers/hv/hv.c > @@ -193,8 +193,10 @@ void hv_synic_free(void) > struct hv_per_cpu_context *hv_cpu > = per_cpu_ptr(hv_context.cpu_context, cpu); > > - free_page((unsigned long)hv_cpu->synic_event_page); > - free_page((unsigned long)hv_cpu->synic_message_page); > + if (!hv_isolation_type_snp() && !hv_root_partition) { > + free_page((unsigned long)hv_cpu->synic_event_page); > + free_page((unsigned long)hv_cpu->synic_message_page); > + } > free_page((unsigned long)hv_cpu->post_msg_page); > } > > -- > 2.25.1
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index c7f7652932ca..a10cf642c9ad 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -193,8 +193,10 @@ void hv_synic_free(void) struct hv_per_cpu_context *hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); - free_page((unsigned long)hv_cpu->synic_event_page); - free_page((unsigned long)hv_cpu->synic_message_page); + if (!hv_isolation_type_snp() && !hv_root_partition) { + free_page((unsigned long)hv_cpu->synic_event_page); + free_page((unsigned long)hv_cpu->synic_message_page); + } free_page((unsigned long)hv_cpu->post_msg_page); }