Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6942FC433DF for ; Thu, 14 May 2020 15:02:40 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 377D8205CB for ; Thu, 14 May 2020 15:02:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 377D8205CB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jZFNL-0004HR-1f; Thu, 14 May 2020 15:02:19 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jZFNK-0004HM-7b for xen-devel@lists.xenproject.org; Thu, 14 May 2020 15:02:18 +0000 X-Inumbo-ID: e6cfaf38-95f3-11ea-a4a3-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e6cfaf38-95f3-11ea-a4a3-12813bfff9fa; Thu, 14 May 2020 15:02:17 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AE37EAC7B; Thu, 14 May 2020 15:02:18 +0000 (UTC) Subject: Re: [PATCH v8 09/12] xen: add runtime parameter access support to hypfs To: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= References: <20200508153421.24525-1-jgross@suse.com> <20200508153421.24525-10-jgross@suse.com> <76ed2db5-6091-959a-8224-0a77e9cc4c45@suse.com> <76cf4476-f8b8-dc44-9e68-bfa92a3fcd2a@suse.com> <33daeea9-a038-b153-44b5-d9a8a11ae21f@suse.com> From: Jan Beulich Message-ID: <95a5644c-e208-57bc-2f47-13581a16b568@suse.com> Date: Thu, 14 May 2020 17:02:14 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <33daeea9-a038-b153-44b5-d9a8a11ae21f@suse.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Jun Nakajima , xen-devel@lists.xenproject.org, Volodymyr Babchuk , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 14.05.2020 16:56, Jürgen Groß wrote: > On 14.05.20 14:10, Jan Beulich wrote: >> On 14.05.2020 13:48, Jürgen Groß wrote: >>> On 14.05.20 12:20, Jan Beulich wrote: >>>> On 08.05.2020 17:34, Juergen Gross wrote: >>>>> --- a/xen/common/grant_table.c >>>>> +++ b/xen/common/grant_table.c >>>>> @@ -85,8 +85,43 @@ struct grant_table { >>>>>        struct grant_table_arch arch; >>>>>    }; >>>>>    -static int parse_gnttab_limit(const char *param, const char *arg, >>>>> -                              unsigned int *valp) >>>>> +unsigned int __read_mostly opt_max_grant_frames = 64; >>>>> +static unsigned int __read_mostly opt_max_maptrack_frames = 1024; >>>>> + >>>>> +#ifdef CONFIG_HYPFS >>>>> +#define GRANT_CUSTOM_VAL_SZ  12 >>>>> +static char __read_mostly opt_max_grant_frames_val[GRANT_CUSTOM_VAL_SZ]; >>>>> +static char __read_mostly opt_max_maptrack_frames_val[GRANT_CUSTOM_VAL_SZ]; >>>>> + >>>>> +static void update_gnttab_par(struct param_hypfs *par, unsigned int val, >>>>> +                              char *parval) >>>>> +{ >>>>> +    snprintf(parval, GRANT_CUSTOM_VAL_SZ, "%u", val); >>>>> +    custom_runtime_set_var_sz(par, parval, GRANT_CUSTOM_VAL_SZ); >>>>> +} >>>>> + >>>>> +static void __init gnttab_max_frames_init(struct param_hypfs *par) >>>>> +{ >>>>> +    update_gnttab_par(par, opt_max_grant_frames, opt_max_grant_frames_val); >>>>> +} >>>>> + >>>>> +static void __init max_maptrack_frames_init(struct param_hypfs *par) >>>>> +{ >>>>> +    update_gnttab_par(par, opt_max_maptrack_frames, >>>>> +                      opt_max_maptrack_frames_val); >>>>> +} >>>>> +#else >>>>> +#define opt_max_grant_frames_val    NULL >>>>> +#define opt_max_maptrack_frames_val NULL >>>> >>>> This looks latently dangerous to me (in case new uses of these >>>> two identifiers appeared), but I guess my alternative suggestion >>>> will be at best controversial, too: >>>> >>>> #define update_gnttab_par(par, val, unused) update_gnttab_par(par, val) >>>> #define parse_gnttab_limit(par, arg, valp, unused) parse_gnttab_limit(par, arg, valp) >>>> >>>> (placed right here) >>> >>> Who else would use those identifiers not related to hypfs? >> >> I can't see an obvious possible use, but people get creative, i.e. >> you never know. Passing NULL into a function without it being >> blindingly obvious that it won't ever get (de)referenced is an at >> least theoretical risk imo. > > Hmm, what about using a special type for those content variables? > Something like: > > #ifdef CONFIG_HYPFS > #define hypfs_string_var            char * > #else > #define hypfs_string_var            char > #define opt_max_grant_frames_val    0 > #define opt_max_maptrack_frames_val 0 > #endif > > And then use that as type for function parameters? This should make > dereferencing pretty hard. > > Other than that I have no really good idea how to avoid this problem. IOW (as suspected) you don't like my suggestion? Personally I think yours, having more #define-s, is at least not better than mine. Jan