From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
To: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
Bjorn Andersson <andersson@kernel.org>
Cc: Konrad Dybcio <konradybcio@kernel.org>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Rob Clark <robin.clark@oss.qualcomm.com>,
Sean Paul <sean@poorly.run>,
Akhil P Oommen <akhilpo@oss.qualcomm.com>,
Dmitry Baryshkov <lumag@kernel.org>,
Abhinav Kumar <abhinav.kumar@linux.dev>,
Jessica Zhang <jesszhan0024@gmail.com>,
Marijn Suijten <marijn.suijten@somainline.org>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-hardening@vger.kernel.org, dri-devel@lists.freedesktop.org,
freedreno@lists.freedesktop.org
Subject: Re: [PATCH v3 2/3] soc: qcom: ubwc: Get HBB from SMEM
Date: Tue, 13 Jan 2026 16:31:15 +0100 [thread overview]
Message-ID: <befc5600-5cfd-4134-928c-80e3b1b4102a@oss.qualcomm.com> (raw)
In-Reply-To: <nhgxvv5bm3bevq4qkqnew6gaqlwiaicrs7yjckg26fgwnffqj5@u2phabfukljx>
On 1/10/26 11:45 AM, Dmitry Baryshkov wrote:
> On Fri, Jan 09, 2026 at 11:50:46AM -0600, Bjorn Andersson wrote:
>> On Fri, Jan 09, 2026 at 05:21:10AM +0200, Dmitry Baryshkov wrote:
>>> On Thu, Jan 08, 2026 at 11:49:54AM -0600, Bjorn Andersson wrote:
>>>> On Thu, Jan 08, 2026 at 04:45:49PM +0200, Dmitry Baryshkov wrote:
>>>>> On Thu, Jan 08, 2026 at 03:21:51PM +0100, Konrad Dybcio wrote:
>>>>>> From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
>>>>>>
>>>>>> To make sure the correct settings for a given DRAM configuration get
>>>>>> applied, attempt to retrieve that data from SMEM (which happens to be
>>>>>> what the BSP kernel does, albeit with through convoluted means of the
>>>>>> bootloader altering the DT with this data).
>>>>>>
>>>>>> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
>>>>>>
>>>>>> ---
>>>>>> I'm not sure about this approach - perhaps a global variable storing
>>>>>> the selected config, which would then be non-const would be better?
>>>>>
>>>>> I'd prefer if const data was const, split HBB to a separate API.
>>>>>
>>>>
>>>> I agree, but I'd prefer to avoid a separate API for it.
>>>>
>>>> Instead I'd like to either return the struct by value (after updating
>>>> the hbb), but we then loose the ability to return errors, or by changing
>>>> the signature to:
>>>>
>>>> int qcom_ubwc_config_get_data(struct qcom_ubwc_cfg_data *data)
>>>>
>>>> This costs us an additional 16 bytes in each client (as the pointer is
>>>> replaced with the data), but I think it's a cleaner API.
>>>
>>> What about:
>>>
>>> const struct qcom_ubwc_cfg_data qcom_ubwc_config_get_data(u32 *hbb)
>>>
>>> I really want to keep the data as const and, as important, use it as a
>>> const pointer.
>>>
>>
>> I guess the question is what are you actually trying to achive; my goal
>> was to keep the base data constant, but I'm guessing that you also want
>> to retain the "const" classifier in the client's context struct (e.g.
>> the "mdss" member in struct dpu_kms)
>>
>> If we're returning the data by value, there's no way for you to mark
>> it as "const" in the calling code's context object (as by definition you
>> shouldn't be able to change the value after initializing the object).
>
> And I, of course, misssed one star:
>
> const struct qcom_ubwc_cfg_data *qcom_ubwc_config_get_data(u32 *hbb)
>
> This leaks the knowledge that HBB is slightly different kind of property
> than the rest of UBWC data.
>
>>
>> You also can't return the data by value and then track it by reference -
>> as that value lives on the stack. This has the benefit of making the
>> lifecycle of that object clear (it lives in each client) - but perhaps
>> not a goal of ours...
>>
>> How come the ubwc config is const but the hbb isn't?
>>
>>
>> If we want both the per-target data to remain const and data in the
>> client's context to be carrying the const qualifier, the one solution I
>> can see is:
>>
>> const struct qcom_ubwc_cfg_data *qcom_ubwc_config_get_data(void)
>> {
>> const struct qcom_ubwc_cfg_data *data;
>> static struct qcom_ubwc_cfg_data cfg;
>> int hbb;
>>
>> ...
>>
>> data = of_machine_get_match_data(qcom_ubwc_configs);
>> ...
>>
>> hbb = qcom_smem_dram_get_hbb();
>> ...
>>
>> cfg = *data;
>> cfg.highest_bank_bit = hbb;
>>
>> return &cfg;
>> }
>>
>> But we'd need to deal with the race in cfg assignment...
>
> static struct qcom_ubwc_cfg_data *cfg;
> static DEFINE_MUTEX(cfg_mutex);
> const struct qcom_ubwc_cfg_data *qcom_ubwc_config_get_data(void)
> {
> const struct qcom_ubwc_cfg_data *data;
> int hbb;
>
> guard(mutex)(&cfg_mutex);
>
> if (cfg)
> return cfg;
>
> data = of_machine_get_match_data(qcom_ubwc_configs);
> if (!data)
> return ERR_PTR(-ENOMEM);
>
> hbb = qcom_smem_dram_get_hbb();
> if (hbb = -ENODATA)
> hbb = 15; /* I think it was default */
> else if (hbb < 0)
> return ERR_PTR(hbb);
>
> cfg = kmemdup(data, sizeof(*data), GFP_KERNEL);
> if (!cfg)
> return ERR_PTR(-ENOMEM);
>
> cfg->highest_bank_bit = hbb;
>
> return cfg;
> }
>
> This potentially leaks sizeof(*data) memory if the module gets removed.
> Granted that all users also use qcom_ubwc_config_get_data() symbol, it
> should be safe to kfree(cfg) on module removal.
I really don't understand why you'd want a separate API for hbb, if
hbb is already available from the larger struct *and* if a driver needs
to know about the value of hbb, it really needs to know about all the
other values as well
Konrad
next prev parent reply other threads:[~2026-01-13 15:31 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 14:21 [PATCH v3 0/3] Retrieve information about DDR " Konrad Dybcio
2026-01-08 14:21 ` [PATCH v3 1/3] soc: qcom: smem: Expose DDR data " Konrad Dybcio
2026-01-09 13:36 ` Mukesh Ojha
2026-01-27 14:22 ` Konrad Dybcio
2026-01-09 18:08 ` Bjorn Andersson
2026-01-14 16:36 ` kernel test robot
2026-01-08 14:21 ` [PATCH v3 2/3] soc: qcom: ubwc: Get HBB " Konrad Dybcio
2026-01-08 14:45 ` Dmitry Baryshkov
2026-01-08 17:49 ` Bjorn Andersson
2026-01-09 3:21 ` Dmitry Baryshkov
2026-01-09 17:50 ` Bjorn Andersson
2026-01-10 10:45 ` Dmitry Baryshkov
2026-01-13 15:31 ` Konrad Dybcio [this message]
2026-01-13 16:29 ` Dmitry Baryshkov
2026-02-17 12:59 ` Konrad Dybcio
2026-02-17 22:53 ` Dmitry Baryshkov
2026-02-17 23:08 ` Rob Clark
2026-01-13 15:36 ` Konrad Dybcio
2026-01-08 14:21 ` [PATCH v3 3/3] drm/msm/adreno: Trust the SSoT UBWC config Konrad Dybcio
2026-01-08 14:46 ` Dmitry Baryshkov
2026-01-16 18:32 ` Rob Clark
2026-02-28 22:16 ` Val Packett
2026-01-09 8:20 ` [PATCH v3 0/3] Retrieve information about DDR from SMEM Neil Armstrong
2026-01-09 10:15 ` Konrad Dybcio
2026-01-09 8:31 ` Neil Armstrong
2026-01-09 19:11 ` Connor Abbott
2026-01-09 20:41 ` Rob Clark
2026-01-09 21:03 ` Connor Abbott
2026-01-10 4:17 ` Rob Clark
2026-02-17 11:23 ` Konrad Dybcio
2026-02-18 15:58 ` Connor Abbott
2026-01-10 10:49 ` Dmitry Baryshkov
2026-01-13 15:31 ` Konrad Dybcio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=befc5600-5cfd-4134-928c-80e3b1b4102a@oss.qualcomm.com \
--to=konrad.dybcio@oss.qualcomm.com \
--cc=abhinav.kumar@linux.dev \
--cc=airlied@gmail.com \
--cc=akhilpo@oss.qualcomm.com \
--cc=andersson@kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=gustavoars@kernel.org \
--cc=jesszhan0024@gmail.com \
--cc=kees@kernel.org \
--cc=konradybcio@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lumag@kernel.org \
--cc=marijn.suijten@somainline.org \
--cc=robin.clark@oss.qualcomm.com \
--cc=sean@poorly.run \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®