Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2851747pxb; Fri, 12 Feb 2021 03:07:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJw61kdXd/objj/KKTK0E6A1wjffJC8TIGEB2KKs3x1f1gEgRxAJJ0ywRynRsw3TAiRdINdL X-Received: by 2002:aa7:cac6:: with SMTP id l6mr2759986edt.357.1613128031207; Fri, 12 Feb 2021 03:07:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613128031; cv=none; d=google.com; s=arc-20160816; b=h99FxPn82VfZqwWyWj+rMOuGJOew1qXQ+i5u9x30qA/DQkykYcsAMTNn110joDIE18 cKXVLa/RtfTajHV/URN0JIBOMl5F4V6FOBk/sET7zzYYRwFZzl5P1ofGrXIcgLjIXt4L /lfoKnHlM9ropZX/VdLnliLkM35hPaDIBuypvBhpYZIyaEAvZlE1tYs95NTtyJxe7M3M 5wXym0ofBxR4BopJAdXqKE3fmpz2rW7xC/RNjQImS3d6qhFNiw+XlCBPcnYvNcy76nx1 Z9sBKdliaxwbQ9Ty74wh1cEHqlq7memYNFJatRD2g37f2eenETzHVgG0q7NrHWCch8Ie qZFA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=p4YARn8JzUhJvALGOL90mmJkYvO4mVQhohGeldmTV6s=; b=oD7u4X6D+q877k1N13bxeH4iDaj871K815o3grwqJUtepW8/sJUGbQ8CvyZ2H+lyjw IfzhIJyCZRDOC/mmoOd6m1dm9nA4tQfwizAlMHR+/3ses6uvM0P51XN+DTYW1J7Gq6dz t7IjbOnK5okV4tA0nMmeKi5o10odpNPWmg8kiyNW8dwDJV1WVkg76+F31ggwHXjXG/4u qN8BEDm4zJvy0Qe+m/WZxDAnNtUdEpd2X9PjAOr1RyQzcjgB7d0bSXKS+MU6P/Ky2nAC tM1Y7x8emnhS0YXRPufl7gf+rXPJBOwoG//HJ888KOYfSjjQ7QYdy2GOf74Z/WyWzQrE GZ4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kBSfJavI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rh23si5766721ejb.516.2021.02.12.03.06.48; Fri, 12 Feb 2021 03:07:11 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kBSfJavI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229653AbhBLLFh (ORCPT + 99 others); Fri, 12 Feb 2021 06:05:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:58982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbhBLLDC (ORCPT ); Fri, 12 Feb 2021 06:03:02 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 957B864E76; Fri, 12 Feb 2021 11:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613127741; bh=EV5+BiyQb7D8LxS1xWP15szpGr2r00+u7btJALPMt48=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kBSfJavIogZBIU6VDq2qfB65gYwffaP8ys/pJnWQsR+x0i0m1tv0QgigtbkG+bfT4 F2OWVGaMX88geuymskFNFhEIJWu8Xbw0rlOMEX0QYCfS/rpVlVgIo93wvPIQBbbqdn amg1hMgDjWeU9Bvogsibt4/gu+nJ3mlcM5ctRlxA= Date: Fri, 12 Feb 2021 12:02:18 +0100 From: Greg Kroah-Hartman To: Shuo A Liu Cc: linux-next@vger.kernel.org, Stephen Rothwell , Randy Dunlap , linux-kernel@vger.kernel.org Subject: Re: [PATCH] virt: acrn: Fix vCPU removing code build error Message-ID: References: <20210212045724.77846-1-shuo.a.liu@intel.com> <20210212105853.GF15601@shuo-intel.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210212105853.GF15601@shuo-intel.sh.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 12, 2021 at 06:58:53PM +0800, Shuo A Liu wrote: > Hi Greg, > > On Fri 12.Feb'21 at 8:52:33 +0100, Greg Kroah-Hartman wrote: > > On Fri, Feb 12, 2021 at 12:57:24PM +0800, shuo.a.liu@intel.com wrote: > > > From: Shuo Liu > > > > > > vCPU removing code depends on CONFIG_HOTPLUG_CPU as it uses remove_cpu() > > > and add_cpu(). Make the vCPU removing interface building with > > > CONFIG_HOTPLUG_CPU. > > > > > > ../drivers/virt/acrn/hsm.c: In function ‘remove_cpu_store’: > > > ../drivers/virt/acrn/hsm.c:389:3: error: implicit declaration of function ‘remove_cpu’; [-Werror=implicit-function-declaration] > > > remove_cpu(cpu); > > > > > > ../drivers/virt/acrn/hsm.c:402:2: error: implicit declaration of function ‘add_cpu’; [-Werror=implicit-function-declaration] > > > add_cpu(cpu); > > > > > > Fixes: 279dcf693ac7 ("virt: acrn: Introduce an interface for Service VM to control vCPU") > > > Reported-by: Randy Dunlap > > > Acked-by: Randy Dunlap # build-tested > > > Signed-off-by: Shuo Liu > > > --- > > > drivers/virt/acrn/hsm.c | 4 ++++ > > > 1 file changed, 4 insertions(+) > > > > > > diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c > > > index 1f6b7c54a1a4..e340788aacdf 100644 > > > --- a/drivers/virt/acrn/hsm.c > > > +++ b/drivers/virt/acrn/hsm.c > > > @@ -372,6 +372,7 @@ static int acrn_dev_release(struct inode *inode, struct file *filp) > > > return 0; > > > } > > > > > > +#ifdef CONFIG_HOTPLUG_CPU > > > static ssize_t remove_cpu_store(struct device *dev, > > > struct device_attribute *attr, > > > const char *buf, size_t count) > > > @@ -403,9 +404,12 @@ static ssize_t remove_cpu_store(struct device *dev, > > > return ret; > > > } > > > static DEVICE_ATTR_WO(remove_cpu); > > > +#endif > > > > > > static struct attribute *acrn_attrs[] = { > > > +#ifdef CONFIG_HOTPLUG_CPU > > > &dev_attr_remove_cpu.attr, > > > +#endif > > > NULL > > > }; > > > > > > > > > > Shouldn't the real solution for this be that remove_cpu() and add_cpu() > > have function prototypes for when this is not enabled in the kernel > > build? > > Something like this in linux/cpu.h? > > diff --git a/include/linux/cpu.h b/include/linux/cpu.h > index 3aaa0687e8df..94a578a96202 100644 > --- a/include/linux/cpu.h > +++ b/include/linux/cpu.h > @@ -108,6 +108,8 @@ static inline void cpu_maps_update_done(void) > { > } > > +static inline int add_cpu(unsigned int cpu) { return 0;} > + > #endif /* CONFIG_SMP */ > extern struct bus_type cpu_subsys; > > @@ -137,6 +139,7 @@ static inline int cpus_read_trylock(void) { return > true; } > static inline void lockdep_assert_cpus_held(void) { } > static inline void cpu_hotplug_disable(void) { } > static inline void cpu_hotplug_enable(void) { } > +static inline int remove_cpu(unsigned int cpu) { return -EPERM; } > static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) > { } > #endif /* !CONFIG_HOTPLUG_CPU */ > > > > > > Putting #ifdef in .c files like this is not a good idea at all. > > > > Then, at runtime, you can determine if you need to create this sysfs > > file or not, as you do not want to expose it to userspace if the kernel > > can not handle it, right? > > Right. I don't want to expose the sysfs to userspace if the kernel built > w/o CONFIG_HOTPLUG_CPU. But how to implement that if #ifdef is not used? > misc_register() creates sysfs with .groups (acrn_attr_groups) > unconditionally, then userspace can see the interface even it doesn't > work. Use the is_visible() callback for your attribute group. thanks, greg k-h