From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 4A512427A19 for ; Tue, 28 Apr 2026 10:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777373001; cv=none; b=qwjpvtObWNBavAWM0WibLtHdKIchtvjyBIFNZ50PDxnUXiCsxD5CK6jvQ+R6NPkJQGi6G124USmrvAd62venJ4JbDbNX5579YLsMa/UOetfL8WjIODx2Q6bQBzEHfjRKz2VWACXun+iiSSOWNjsR6s3NlqZAU3CVUes4vygmARM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777373001; c=relaxed/simple; bh=D84N/KUvgGLLkb6ue7eX5V9qeV2gwsd7cxmMuguzGNc=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=pVPItb9bzRHnomsszZw94Kxs+f76WNxxJHIS6lp51Gb/7mT0AQa2o2bRgCPKb9zTJIGOgPL8EEMen5+JrUu4iFwZY9zIyiHUR4e9mbSFjDculDRPlwNOsLYu/5yCT6UDCth8hPvuhnWnqBSklnnV6GofV7ZvwRaS2t15q/1zJM0= 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=Vuo2/vJK; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=MSlvSzRF; arc=none smtp.client-ip=205.220.168.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="Vuo2/vJK"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="MSlvSzRF" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63S9hZLp2045259 for ; Tue, 28 Apr 2026 10:43:14 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= PIxcKhZ7J5p7muppYgPV9govSvoDNSjvHD1kzMfuUEk=; b=Vuo2/vJKJxvT/msW IjyTCf5jj6U4408fvQVojQQBOAZNkGDzXEOv2ds7nFrZc2g7HHb/e1yMOQIWyaEV ALALYgKZe1lUZFl+Al4YaKOf26wC0g+JRzxcQoTfei+CAsIVCVFoE/e+wHHID9HH fy+QqcctuAU4y2qZl0XAYZd0blsFu2KklI4z8wTYVQqUTv+2wqH2dCuONaHBLHse QseO1jCRhFoL/mOeTPs/8UkjjZfO2qNzny1SEdI9z75SHSAxXHnvopRIBzIuDt4n 0FhGqMjDpIpW6CfrOfCbrsXcKl86jrM5MnKx9ZzFdNyxJm8rpUJG5Ixf07W45C6j uQdonA== Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dttgyr705-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 28 Apr 2026 10:43:14 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-2eaed3d96d7so3228076eec.0 for ; Tue, 28 Apr 2026 03:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1777372994; x=1777977794; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=PIxcKhZ7J5p7muppYgPV9govSvoDNSjvHD1kzMfuUEk=; b=MSlvSzRF5qeooF3nfj2kn2LuJFiZj0PRV83JzUFT8ImMHvKDRQx/YxHTfCGqXVUoRN DCXPL0i6lQiDm0umgeYAhGHIYxrrNe2AFaEbSeT6ZH+BLi9dRLWQbLg9LP+TbWZS5N2o vzWHMJoeRkfCAObsdXlrBMK2URECu/56xcbjK8bURgTelYUIwGEsTnYc67h2nCUbYS8R bjp544yqbFabI+yH3uueMRWmeS1cXQConoYMtF1suyDh42Cog+4WHOkNpXzJGmAQZOXZ NDvzQihTNgHt2uNGcTf3DwYMtsBBUx2fZS0bRO/jPYFftSblxxtQ3F+KaIuivUt0U4l9 gqAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777372994; x=1777977794; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PIxcKhZ7J5p7muppYgPV9govSvoDNSjvHD1kzMfuUEk=; b=Mz0JGwtM0STSVOqHBYOvwBbwG6RZ8IBeljkWpsFiFZ/za5bpAxRfZ4Y3hYZTdz3dNl D8YicI25tqMhHJNfU7cOKRinQozzj1YUCj3TwUefvUY4FOc648sPNqy649IwF2poMpvE JEJIfcLSD2tzA6GyK7SRlbATQDAo4FuyTZjl8P8JzW18j5WGqEuCPN1Ye+nAL4YiXL0e WVqnL/u0xoddpJBZ8vWSzNbPEqMOj68ENjEPePUmUHDQexqrrvNOg+k3Frqzx2XopPtQ y6nm07ifHmdalWYFVW999Q7ESy+lM8Yv9gtWY83Eq9RT2ypNL6myeA9FnNtXxpQxZcIV ZUYA== X-Forwarded-Encrypted: i=1; AFNElJ9/4R7jZWmMUWaAqFwuyXmRuf+Z/nisyEyMo9yXJqlMfojwt+9j+XhnRnDKOuIvey/xbmKoKfxxO7Kwn4A=@vger.kernel.org X-Gm-Message-State: AOJu0Yzxs1pnaAApS7DAtoo2skBBDYmpUqxRRGHFsmpnUCe0HCVMt5wO GnoCFAcyvRGanSHDilPcP4NQEJjIjIHmPkfQ9pNfElE9zRocYqoSuVXeJgTRr/WwIl33LGUT1JO rXY8bnBolVbZFwMeR/qczNQZfNKyy+fMp7O/lRg9RsktOgZIUo+0TLWPUCFtILp67L0E= X-Gm-Gg: AeBDievgUXHKLU5a6P6nrcPhWvLV9ZQN2/f1MhIl+nU+wgPc04hV3K0tOzGqhAcwDzI ZkFm9UbEFBIovVJKIbwHOABDceh02dp9/kYq6xAYaVtP9ze6KQ0y8m3C8pjdtZsP7yQxvPE3T6J wDiuyRRI1r6R4Xh/elBwqn4FVzoTZS1MTdDLNS4fHtZai5zQ4Z6WGnb4PWtO8819dpWTo5C7p6H 9haiIWLYjzvGoH/39P63Yr6umrKZHUuPOiKHhWzU7erqOTdQ8Ph0iWHXXAUW4rwUTxCYvzKmHVC 5EsAqHat8A4slwZuz/L621MzDtjm3m0IZY4C0mM8KIabFlj5Ot6F84JH+GY/2S1wnScIdNjm93V dRawwyUcxtNqRs8KlaIxhrA+Br8Cko4yTaMa6V2q02fFbrwxxBPgwRlq2NfqdM8/melajwvDiFv XZj4POfLDUdwNaEA== X-Received: by 2002:a05:7300:dc98:b0:2d3:f3fc:bb6b with SMTP id 5a478bee46e88-2ed09fde238mr1159788eec.1.1777372993851; Tue, 28 Apr 2026 03:43:13 -0700 (PDT) X-Received: by 2002:a05:7300:dc98:b0:2d3:f3fc:bb6b with SMTP id 5a478bee46e88-2ed09fde238mr1159764eec.1.1777372993185; Tue, 28 Apr 2026 03:43:13 -0700 (PDT) Received: from [10.110.45.159] (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ed0a106524sm1987174eec.23.2026.04.28.03.43.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Apr 2026 03:43:12 -0700 (PDT) Message-ID: Date: Tue, 28 Apr 2026 18:43:08 +0800 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 2/3] dm-inlinecrypt: add target for inline block device encryption From: Linlin Zhang To: Benjamin Marzinski Cc: linux-block@vger.kernel.org, ebiggers@kernel.org, mpatocka@redhat.com, gmazyland@gmail.com, linux-kernel@vger.kernel.org, adrianvovk@gmail.com, dm-devel@lists.linux.dev, quic_mdalam@quicinc.com, israelr@nvidia.com, hch@infradead.org, axboe@kernel.dk References: <20260410134031.2880675-1-linlin.zhang@oss.qualcomm.com> <20260410134031.2880675-3-linlin.zhang@oss.qualcomm.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: pDzUCB_hXeSF26yP09glI85z4--Z3xrQ X-Proofpoint-GUID: pDzUCB_hXeSF26yP09glI85z4--Z3xrQ X-Authority-Analysis: v=2.4 cv=cb7iaHDM c=1 sm=1 tr=0 ts=69f08f42 cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=JYp8KDb2vCoCEuGobkYCKw==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=1XWaLZrsAAAA:8 a=EUspDBNiAAAA:8 a=zAVYknurB8viCDo1gd4A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=bBxd6f-gb0O0v-kibOvt:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDI4MDA5NiBTYWx0ZWRfX2sxrZxNqSLbn YPj/Y4XF9E7eqdMXEloavszVNBXyE/JbFieuDmBYH2bl6EHQIFAfhTi0jAPChxLkWryhhPzdk6v tx/lD5iX3ho2FkduOYFCBqHMQZtgINwZtmZugTge+/892vEMASvdyGbdf5IQnV/Kf6r1rP5NCJX 01zoNC8CxPl2tZtHsNMUEcuf2kn9nfCKp7UrWrm8gbN4v2P37iX0r/j6C5STMbADsvBV8+uDTkE YibB4XiatRh1q4L+GuyGrONS68khOaYKXdZGPmu7UI7mw4EWOEWoUfSOt734guCdNjN46irftAc qZ1sP/j2cS32WYzqdkM8h4QHBybojYjyf1BYl05u9En2mQUA9tLPvUiJAj665CMuHOqE2t8sRmS ouMajndkbzPz5NyPG7EuNPkxLEOMl4vPuaZFOLCnXDGFTkvKleYMWchKViW5IeSu6HcN7WGVwO6 ZevOJfKpvOMcOZSZQcw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-28_02,2026-04-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 clxscore=1015 impostorscore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 spamscore=0 priorityscore=1501 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604280096 Correct the response to Benjamin's comments. On 4/27/2026 8:20 PM, Linlin Zhang wrote: > > > On 4/27/2026 9:19 AM, Benjamin Marzinski wrote: >> On Fri, Apr 10, 2026 at 06:40:30AM -0700, Linlin Zhang wrote: >>> From: Eric Biggers >>> + >>> +static int inlinecrypt_map(struct dm_target *ti, struct bio *bio) >>> +{ >>> + const struct inlinecrypt_ctx *ctx = ti->private; >>> + sector_t sector_in_target; >>> + u64 dun[BLK_CRYPTO_DUN_ARRAY_SIZE] = {}; >>> + >>> + bio_set_dev(bio, ctx->dev->bdev); >>> + >>> + /* >>> + * If the bio is a device-level request which doesn't target a specific >>> + * sector, there's nothing more to do. >>> + */ >>> + if (bio_sectors(bio) == 0) >>> + return DM_MAPIO_REMAPPED; >>> + >>> + /* >>> + * The bio should never have an encryption context already, since >>> + * dm-inlinecrypt doesn't pass through any inline encryption >>> + * capabilities to the layer above it. >>> + */ >>> + if (WARN_ON_ONCE(bio_has_crypt_ctx(bio))) >>> + return DM_MAPIO_KILL; >>> + >>> + /* Map the bio's sector to the underlying device. (512-byte sectors) */ >>> + sector_in_target = dm_target_offset(ti, bio->bi_iter.bi_sector); >>> + bio->bi_iter.bi_sector = ctx->start + sector_in_target; >>> + /* >>> + * If the bio doesn't have any data (e.g. if it's a DISCARD request), >>> + * there's nothing more to do. >>> + */ >>> + if (!bio_has_data(bio)) >>> + return DM_MAPIO_REMAPPED; >>> + >>> + /* Calculate the DUN and enforce data-unit (crypto sector) alignment. */ >>> + dun[0] = ctx->iv_offset + sector_in_target; /* 512-byte sectors */ >>> + if (dun[0] & ((ctx->sector_size >> SECTOR_SHIFT) - 1)) >>> + return DM_MAPIO_KILL; >> >> If ctx->iv_offset is not a multiple of ctx->sector_size, this will >> always fail. ctx->iv_offset should probably get validated in >> inlinecrypt_ctr() > > ACK > > Yes, this assumes iv_offset is aligned to sector_size when large crypto > sectors are used. That’s a requirement of dm-inlinecrypt semantics, and > adding an explicit check in inlinecrypt_ctr() would make this fail earlier > and more clearly. Sorry, the last response is wrong. No need to add check in inlinecrypt_ctr(). iv_offset is the starting offset for IVs that are generated as if the target were preceded by iv_offset 512-byte sectors. I think this concern is based on an implicit assumption that sector_in_target is always data-unit (crypto sector) aligned. In this target, however, sector_in_target is derived from dm_target_offset() and is in 512-byte sectors, so it is not guaranteed to be a multiple of (sector_size >> SECTOR_SHIFT). The intended alignment requirement is on the *final* DUN, i.e. on (iv_offset + sector_in_target) in 512-byte sector units, before it gets shifted down to crypto-sector units. That's why the code checks alignment on the sum (iv_offset + sector_in_target). With this definition, iv_offset itself does not need to be aligned to the data-unit size; any non-negative value is valid as long as the resulting DUN for a given bio is data-unit aligned. For example, iv_offset = 1 can still be valid when sector_in_target is 7 (4096-byte sector case), since their sum is aligned. Validating iv_offset alone in inlinecrypt_ctr() would therefore reject configurations that are otherwise correct per the (sum-based) DUN definition. So I believe the runtime check in ->map() is the right place to enforce the data-unit alignment constraint, as it has the actual bio offset (sector_in_target) needed to evaluate the constraint. Let me know if you'd prefer we document this more explicitly in the map() argument description; I'm fine adding a short note about the iv_offset units and the sum-based alignment rule. > >> >> -Ben >> >>> + dun[0] >>= ctx->sector_bits - SECTOR_SHIFT; /* crypto sectors */ >>> + >>> + /* >>> + * This check isn't necessary as we should have calculated max_dun >>> + * correctly, but be safe. >>> + */ >>> + if (WARN_ON_ONCE(dun[0] > ctx->max_dun)) >>> + return DM_MAPIO_KILL; >>> + >>> + bio_crypt_set_ctx(bio, &ctx->key, dun, GFP_NOIO); >>> + >>> + /* >>> + * Since we've added an encryption context to the bio and >>> + * blk-crypto-fallback may be needed to process it, it's necessary to >>> + * use the fallback-aware bio submission code rather than >>> + * unconditionally returning DM_MAPIO_REMAPPED. >>> + * >>> + * To get the correct accounting for a dm target in the case where >>> + * __blk_crypto_submit_bio() doesn't take ownership of the bio (returns >>> + * true), call __blk_crypto_submit_bio() directly and return >>> + * DM_MAPIO_REMAPPED in that case, rather than relying on >>> + * blk_crypto_submit_bio() which calls submit_bio() in that case. >>> + */ >>> + if (__blk_crypto_submit_bio(bio)) >>> + return DM_MAPIO_REMAPPED; >>> + return DM_MAPIO_SUBMITTED; >>> +} >>> + >>> +MODULE_AUTHOR("Eric Biggers "); >>> +MODULE_AUTHOR("Linlin Zhang "); >>> +MODULE_DESCRIPTION(DM_NAME " target for inline encryption"); >>> +MODULE_LICENSE("GPL"); >>> -- >>> 2.34.1 >>> >> >