From patchwork Wed Nov 23 15:58:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 25074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2879993wrr; Wed, 23 Nov 2022 08:10:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ZzZJfGRADN/Dx/XQytKFwXWeg2OERagDXkAP0QxNixOq1uW3h3u64N0sZA397N4g8W++r X-Received: by 2002:a17:906:d85:b0:7ae:3a88:9487 with SMTP id m5-20020a1709060d8500b007ae3a889487mr24246921eji.193.1669219816323; Wed, 23 Nov 2022 08:10:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669219816; cv=none; d=google.com; s=arc-20160816; b=Ec/B/O/AhlYP/BILdiTeKDErYqXysK44dinbFdTvV7YjJlJRLUQkThyUqwpj2OU4zY EIUnoezCgQZyZo9lgUlWyQzs1XT32lo241Iift6ryIJjMdPBNbnTYSEf5vIvj8hilDiX 9vHe4qbsM8JJigHm6DFUSxxCcUuGSyrlBKjuU1F9giI/4E1/Ic+T8x/N9vofDIDdXBic XWWzdtJhY8dMucz1vqD8NQMxYf0be4AobH/sS7C8+QzuJeF1w+lbxe/ed6F73B2RlqHQ 1SH36k4KJWd/+U07irhmJkULGRdz7Qyrj+75dl/srdSQm00mbDKQaesIvBBuLidGbucw 8pYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=To62y6QkhaWyW1JO6g3IuAtzrmtlvDI7Gl6nK1Ar/Bw=; b=r5BWqohzHCMYjMVR+hLX/23QhKuBKN/Vc/cdKNln5k8odDC0LV83HA3aMfJ0ppKify 1U0fUTLoOemlk3N7aOfIAeU9yx5SUNYQqL4BEB3X3zvZGRs4soATr5dsRzQR7ZqHEcJW 0lku27Phy5j4z9vX4FdpdxSyPJlj4UJVMxjvBojTUB+ao1pdcnXTqEKhdi4KGnookFny pZOg4rgVDEA35OhpWd7oY2M4ExVk3GgqriqCsIS9qoXBTMr7Q9lmbhaCZUIWbChXqTHO 497knmH3cENMWmpakbVU2GFdF6H0UTLJcAHnNYS4/eeNXBFcSiVEmXitvdBS/ohdHoni qW1g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h17-20020a1709063c1100b007adc4a0aeb5si11752358ejg.873.2022.11.23.08.09.48; Wed, 23 Nov 2022 08:10:16 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238543AbiKWQCd (ORCPT + 99 others); Wed, 23 Nov 2022 11:02:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238772AbiKWQCH (ORCPT ); Wed, 23 Nov 2022 11:02:07 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D71BFC4C22 for ; Wed, 23 Nov 2022 08:02:05 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NHQq14xjjzRpDj; Thu, 24 Nov 2022 00:01:33 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.58) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 24 Nov 2022 00:02:03 +0800 From: Xiu Jianfeng To: , , , , , , , CC: , , Subject: [PATCH v2 2/2] x86/xen: Fix memory leak in xen_init_lock_cpu() Date: Wed, 23 Nov 2022 23:58:58 +0800 Message-ID: <20221123155858.11382-3-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221123155858.11382-1-xiujianfeng@huawei.com> References: <20221123155858.11382-1-xiujianfeng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750303838035696948?= X-GMAIL-MSGID: =?utf-8?q?1750303838035696948?= In xen_init_lock_cpu(), the @name has allocated new string by kasprintf(), if bind_ipi_to_irqhandler() fails, it should be freed, otherwise may lead to a memory leak issue, fix it. Fixes: 2d9e1e2f58b5 ("xen: implement Xen-specific spinlocks") Signed-off-by: Xiu Jianfeng Reviewed-by: Juergen Gross --- arch/x86/xen/spinlock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c index 043c73dfd2c9..5c6fc16e4b92 100644 --- a/arch/x86/xen/spinlock.c +++ b/arch/x86/xen/spinlock.c @@ -75,6 +75,7 @@ void xen_init_lock_cpu(int cpu) cpu, per_cpu(lock_kicker_irq, cpu)); name = kasprintf(GFP_KERNEL, "spinlock%d", cpu); + per_cpu(irq_name, cpu) = name; irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, cpu, dummy_handler, @@ -85,7 +86,6 @@ void xen_init_lock_cpu(int cpu) if (irq >= 0) { disable_irq(irq); /* make sure it's never delivered */ per_cpu(lock_kicker_irq, cpu) = irq; - per_cpu(irq_name, cpu) = name; } printk("cpu %d spinlock event irq %d\n", cpu, irq); @@ -98,6 +98,8 @@ void xen_uninit_lock_cpu(int cpu) if (!xen_pvspin) return; + kfree(per_cpu(irq_name, cpu)); + per_cpu(irq_name, cpu) = NULL; /* * When booting the kernel with 'mitigations=auto,nosmt', the secondary * CPUs are not activated, and lock_kicker_irq is not initialized. @@ -108,8 +110,6 @@ void xen_uninit_lock_cpu(int cpu) unbind_from_irqhandler(irq, NULL); per_cpu(lock_kicker_irq, cpu) = -1; - kfree(per_cpu(irq_name, cpu)); - per_cpu(irq_name, cpu) = NULL; } PV_CALLEE_SAVE_REGS_THUNK(xen_vcpu_stolen);