From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A2CC347BAF for ; Thu, 9 Jul 2026 22:04:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783634655; cv=none; b=MASadoVgSysJCiQY5rahDzTcwYQwKDbhqcBU/Hicouu2oqXW8RFee1K5lhW7egbiyjKWBYc8hRDGjbEEwlp38cWvAPNyn7CEkQTcEOe2GCx9v/X7FshimUpf7w37Fd+GWUoGIeZn93+kdEvs4acEYwDACaASGEf+N7JFt9VTfWA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783634655; c=relaxed/simple; bh=iPj4WcX4+OX9Rikgdp71m08tb5Afi5Ai1tOdSzgPOGM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VDy8YTEOEI0Y+ZEXQX7VBw9rst5NCE18iMPd28kiSYvHTXT2rtb0M/0esWx1VoIJ4H4XTxQ9uRTWB8Yvr72RL7EFZkBsctr66fmJw1mZnyZeAS/ld+UdSoc8noftqQ5FnmFACT3YJz36Icwk9X4xQ6m8JCxF1TqY00KqX9hL6tg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=fI7T/fPq; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=GF1Bf4kM; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="fI7T/fPq"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="GF1Bf4kM" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 669HXNO12330060 for ; Thu, 9 Jul 2026 22:04:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= oliFN6INLRWkchr9o0ETL54bVAB74aP+d4p6eJYDfiU=; b=fI7T/fPqRx4DSNFy K3SP23qfxO22CgF7/w5RH6TeKivdYJQN1zrw+9O9X7dW91p7MFjb5wPYOPLnWJku Ib8++e4vv0bG1gyeZtVJjFdKimNiCoe7Th9AzyQdvlGhjl2jB//GXd0u1O6HDGUg xnE0uIhCVHCfEsH5EdUwjMlhzqS2hwzgG8PPf3+C6gQAvb5rQpcz5AtHMt9Z/39B rqN4Hfaiuwfwheqc+JcjdwdryrERwX21cbYAUKmjsX9oM9iZr1RvfFS7vzkBJ0m3 ZrU4EaLINDoAFqcqgHaI0p2bGMPFMfTe1164N3ZvzIrSjJA9uJcnUmhDsbfr2cJf vjJTJw== Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4faf24sdta-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 09 Jul 2026 22:04:12 +0000 (GMT) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-c8952346bb9so194486a12.2 for ; Thu, 09 Jul 2026 15:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1783634651; x=1784239451; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=oliFN6INLRWkchr9o0ETL54bVAB74aP+d4p6eJYDfiU=; b=GF1Bf4kMLK6r7vYrEYqHhINkqoG8iySXsHlxpbQSJDYRA/xK89tDU6g7wO09k5az2K YI+lWIjm8I0RaYRQC2yfmEnqh4Vgceja+IZv2Kxk4v9kpFGWi05PG79I5jqTh+lrv6DC rg29h/CjCP6ooa1wZCLqji67OdL6xi5vVq0SFDM+tRWz6mTEy6qSMgBEl7FD6rhAMauk y/d6Hk1cUTp1fyl7bUw7kBnv6NvLCwMmshIeRl5vaqbnM4Pm0/cXNIkOKEHl0qSnzFn/ xjKrNXPWFYhiXA7tnNIr3T70VCvCQM0bkCZQB8KsXJ5m55PhdLezzAoQa0gHRI6VRk0W nk+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783634651; x=1784239451; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=oliFN6INLRWkchr9o0ETL54bVAB74aP+d4p6eJYDfiU=; b=Vgo3xn6aXfxoCTqH+IAW48tHArgiVtXm2n40Le3iZUpSQA332plTI0tt/ewFWddyXI 0dJkdcgG1lqP6oba6/fw7ZgsV2riAYXOg8ZDU+2LCNkMHpqMMaKr7Wg0dxaJJOeUATuY e9TEp918L/235kRTNXWIOa8BARn/yqrpCIjfOYfecnve7G9mT06yi6lGXNnDrYtPudun 7rMZQtEsN7LvasZVmlzl67BGjuJUaYGmPHoImZVK/JFxRJ25ZtdKQfXZg8f9xSzFvRSD oEkXtV/ITx8y7UWMj3VV6ILbON1kLWIzIem3pAumBs4/JuXVgKCJXD/rQYgOAsSt8dGo tZgQ== X-Forwarded-Encrypted: i=1; AHgh+Roe3FZwtWyLoQwZgNgTYG94dDlkCbhFEqSY+UMxi65rkkxv+bZcT0ZEbU1/HAHgAv55ec/RT0r+EBhi2cE=@vger.kernel.org X-Gm-Message-State: AOJu0YwQWy0QSNny0iqzJSG523O0jbdPsdFmp9PYLif4sU3LpOSxmiH2 ZOuK3HaGQ5TIBUqLCnwPG5bssfFRAGUBtxMZ8l8dTpYlvQsHV52cqvcVshD39GGGUbLn8/OILmw KumAWTJ71zhquFjfbcxisqOjd789NvSJTEsHXXMim/lf3w25ElogLOVBPEc9Q8Wt/l90= X-Gm-Gg: AfdE7clyFKV2EYBtZLs6eKDgzponO5k1ixXNW3xQaDN5qRcuFgH85tcMlPUKcxNqC2v V783bGl/mXHS6m801DMD6z7j393wVegc/eeXmeHNQ4PaI+tp4nQRsq51s7MFc6nnbF6EDlkwsNS 9X8vbfpI4GUggL/t3mdiWeWi5F6a0L2n4R7D2TCfuJFBjqPrDErEFNiya+c3m04jGvphyp+XX7A dc1q7t+p5VHgklu75m9IXtYLtdfHX9RQGjsOSwMfPRZhU5gBcnaJ1d0je5Eiy7F8qW7fwRMmGGL Jr33+0udCO8gfHWw+wy++HZzc32/C2TmdlPtWr3DI5ya5vWz1E9FwVcp4FFdpa/MD7gmnNkTqe6 0VSbgEdFlEoC/qGT2nR6rYvvsfYOBDu8+lyYS+/LNc+pBmT3DjZjHHQKjMRVTRU8qo6o= X-Received: by 2002:a05:6a21:a8a:b0:3bf:a412:ca11 with SMTP id adf61e73a8af0-3c0bd0fa3c0mr10541605637.48.1783634651194; Thu, 09 Jul 2026 15:04:11 -0700 (PDT) X-Received: by 2002:a05:6a21:a8a:b0:3bf:a412:ca11 with SMTP id adf61e73a8af0-3c0bd0fa3c0mr10541564637.48.1783634650596; Thu, 09 Jul 2026 15:04:10 -0700 (PDT) Received: from [10.71.178.173] (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31189cd8234sm23994206eec.9.2026.07.09.15.04.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Jul 2026 15:04:10 -0700 (PDT) Message-ID: Date: Thu, 9 Jul 2026 15:04:09 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] cxl/hdm: Enforce CFMWS memory type policy at decoder commit time To: Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Dan Williams Cc: Ira Weiny , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260709214712.1402933-1-mayank.rana@oss.qualcomm.com> Content-Language: en-US From: Mayank Rana In-Reply-To: <20260709214712.1402933-1-mayank.rana@oss.qualcomm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-GUID: hpeWjG2PC680mac5co3JUMl5oIE9fM21 X-Proofpoint-ORIG-GUID: hpeWjG2PC680mac5co3JUMl5oIE9fM21 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzA5MDIyMSBTYWx0ZWRfX5kyGu0N2I+hE 2pQW4PiacXE7Q1lhT/o6pxaUcrpwYTZbAIzaEqwkuK4eihiF/81uUswPS7rVjEzH/rtGseyuE3R vkj+9nh/io9HNXKHgN4cKRmAjUQU+Mg= X-Authority-Analysis: v=2.4 cv=daKwG3Xe c=1 sm=1 tr=0 ts=6a501adc cx=c_pps a=Qgeoaf8Lrialg5Z894R3/Q==:117 a=JYp8KDb2vCoCEuGobkYCKw==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=EUspDBNiAAAA:8 a=98GTowGNucI4IdNpqSUA:9 a=QEXdDO2ut3YA:10 a=x9snwWr2DeNwDh03kgHS:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzA5MDIyMSBTYWx0ZWRfX3q+TknIzlXn2 ER/lk2/Jsf4xF3nDy4doJ6UouYZ6GZTfsnn45RyCyxeqHsmYB+km2kEC1WnD9VCgIecHk/F7iZe 5CSd141eZcEU0UvtldNQmR93ADLRlGPlrb2RM614jkipJbydhPw+PGNErXKMxjxP3i1Pl4xrrwN IdvDC6WMOL2kSGQHA1s8TPYxLa4Gl7ObqbYoM9WpVEO8J+90CV9tqpv1gO7PpUogjWtEFrS2sKL G1++p7n6f4N6vmbdmMqsnfSX3ox6KAw1DA8evsigK90WCFY0woFA0VoXzhgqIeBH8T1Qyzq5QEi eHIV76WD2pcBHqdEEibjR8vV2IJhzYHY1oU7H0/YYU6CRRvBrpIdp2SZh+qd+VLw/g2i0h3p8oo OmZdXerdDmpQeiY0hZxUvF1GRpX16nK1rmJ4/8Iq8n60a1ze0IlsiowxHKsfOQslEXmQkSFcBx4 UGDrfumzJZHfJBoXBZw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-09_04,2026-07-09_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 bulkscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607090221 Sorry for sending this patch as it was diff to previous v1. Please disregard this patch. I will review again and send update v2. Regards, Mayank On 7/9/2026 2:47 PM, Mayank Rana wrote: > A CXL Fixed Memory Window Structure (CFMWS) in the ACPI CEDT table > carries a restrictions field that describes the memory types a platform > window supports. cfmws_to_decoder_flags() translates this into > CXL_DECODER_F_TYPE2 (HDM-DB permitted) and CXL_DECODER_F_TYPE3 (HDM-H > permitted) flags on the root decoder. > > However, nothing currently prevents a caller from committing an endpoint > or switch decoder whose target_type conflicts with the CFMWS policy: > > - A decoder with target_type == CXL_DECODER_DEVMEM (HDM-DB) can be > committed on a window that lacks CXL_DECODER_F_TYPE2 (HDM-H only). > A dual-capable device will accept HOSTONLY=0 + COMMIT=1 without > asserting COMMIT_ERROR, silently violating platform policy. > > - Symmetrically, a decoder with target_type == CXL_DECODER_HOSTONLYMEM > (HDM-H) can be committed on a window that lacks CXL_DECODER_F_TYPE3 > (HDM-DB only), again violating ACPI CFMWS restrictions. > > Add a check in cxl_decoder_commit() that walks from the decoder's > assigned region to the root decoder and rejects the commit with > -EOPNOTSUPP if the decoder's target_type requires a capability flag that > the CFMWS window does not advertise: > > - CXL_DECODER_DEVMEM requires CXL_DECODER_F_TYPE2 on root decoder > - CXL_DECODER_HOSTONLYMEM requires CXL_DECODER_F_TYPE3 on the root > decoder > > required_flag is initialized to zero so that any future target_type > values not covered by the if/else-if chain leave the enforcement check > a no-op via the leading required_flag && guard. > > This makes the CFMWS restrictions field authoritative for memory type > enforcement in both directions, regardless of individual device capability. > The existing COMMIT_ERROR path in cxld_await_commit() remains as a > secondary safeguard for devices that cannot support the requested mode. > > Fixes: 3e23d17ce198 ("cxl/acpi: Use the ACPI CFMWS to create static decoder objects") > Assisted-by: Claude:claude-sonnet-4-6 > Signed-off-by: Mayank Rana > --- > Changes in v2: > - Extend enforcement to cover both directions: HDM-H commits on > HDM-DB-only windows are now rejected in addition to HDM-DB commits > on HDM-H-only windows (reported by Sashiko AI review) > - Generalize condition from single DEVMEM check to type-dispatch > selecting required_flag based on target_type > - Update commit message and subject to reflect bidirectional policy > - Initialize required_flag = 0 and use explicit else-if for > CXL_DECODER_HOSTONLYMEM; guard enforcement with required_flag && > so unknown target_type values skip the check cleanly > > Testing > ------- > > The bug and fix were validated using QEMU with a modified CXL configuration > on linux-next (v7.2-rc2). > > Two test-only kernel changes were applied (not part of this patch): > > 1. drivers/cxl/acpi.c: cfmws_to_decoder_flags() result overridden to > clear CXL_DECODER_F_TYPE2 and retain only CXL_DECODER_F_TYPE3, > simulating a CFMWS that restricts to HDM-H only (no HDM-DB). > > 2. drivers/cxl/core/hdm.c: cxl_decoder_commit() forced to set > target_type = CXL_DECODER_DEVMEM for endpoint decoders before the > CFMWS check, simulating a dual-capable device committing HDM-DB. > > Bug reproduction (without this patch): > > # cxl create-region -m mem0 -d decoder0.0 -t pmem > cxl region: cmd_create_region: created 1 region > > HDM-DB committed silently despite CFMWS advertising HDM-H only. > No error or warning in dmesg. > > Fix validation (with this patch): > > # cxl create-region -m mem0 -d decoder0.0 -t pmem > cxl region: create_region: region0: failed to commit decode: Operation not supported > cxl region: cmd_create_region: created 0 regions > > dmesg: > cxl_port endpoint2: HDM-DB commit rejected on decoder2.0, \ > CFMWS does not permit this memory type > > HDM-DB commit blocked with -EOPNOTSUPP as expected. > > QEMU invocation: > > qemu-system-x86_64 \ > -kernel bzImage \ > -append "root=/dev/sda rw console=ttyS0" \ > -drive file=rootfs.img,index=0,media=disk,format=raw \ > -M q35,cxl=on -m 4G,maxmem=8G,slots=8 -smp 4 \ > -object memory-backend-file,id=cxl-mem1,share=on,mem-path=/tmp/cxltest.raw,size=256M \ > -object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/tmp/lsa.raw,size=256M \ > -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \ > -device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \ > -device cxl-type3,bus=root_port13,persistent-memdev=cxl-mem1,lsa=cxl-lsa1,id=cxl-pmem0,sn=0x1 \ > -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G \ > -nographic > > drivers/cxl/core/hdm.c | 25 ++++++++++++++++++++----- > 1 file changed, 20 insertions(+), 5 deletions(-) > > diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c > index c26dab185dc8..127a187cdadb 100644 > --- a/drivers/cxl/core/hdm.c > +++ b/drivers/cxl/core/hdm.c > @@ -836,14 +836,29 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld) > } > > /* > - * Enforce HDM-H: reject HDM-DB if CFMWS lacks CXL_DECODER_F_TYPE2. > + * Enforce CFMWS memory type policy: reject commits where the decoder > + * target_type conflicts with the root decoder's CFMWS restrictions. > + * - HDM-DB (DEVMEM) requires CXL_DECODER_F_TYPE2 on the root decoder. > + * - HDM-H (HOSTONLYMEM) requires CXL_DECODER_F_TYPE3 on the root decoder. > + * - Unknown target_type values leave required_flag zero; skip enforcement. > */ > - if (cxld->target_type == CXL_DECODER_DEVMEM && cxld->region) { > + if (cxld->region) { > + unsigned long required_flag = 0; > + const char *type_name; > + > cxlrd = to_cxl_root_decoder(cxld->region->dev.parent); > - if (!(cxlrd->cxlsd.cxld.flags & CXL_DECODER_F_TYPE2)) { > + if (cxld->target_type == CXL_DECODER_DEVMEM) { > + required_flag = CXL_DECODER_F_TYPE2; > + type_name = "HDM-DB"; > + } else if (cxld->target_type == CXL_DECODER_HOSTONLYMEM) { > + required_flag = CXL_DECODER_F_TYPE3; > + type_name = "HDM-H"; > + } > + > + if (required_flag && !(cxlrd->cxlsd.cxld.flags & required_flag)) { > dev_err(&port->dev, > - "HDM-DB commit rejected on %s, CFMWS restricts to HDM-H only\n", > - dev_name(&cxld->dev)); > + "%s commit rejected on %s, CFMWS does not permit this memory type\n", > + type_name, dev_name(&cxld->dev)); > return -EOPNOTSUPP; > } > }