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 6D01638F648 for ; Wed, 29 Apr 2026 12:16:26 +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=1777464987; cv=none; b=pJ7JVG+vxx81ZHO2u30w/b60VPmRrJdKrzVBgSMQjaQmYQqQpwcNqwfAScMT/9bUWByDbrsULrvemAkcuwIVv/fF+m6pJKO1yzJBRlgtuNyG2zbOMsle1xxfNzVVVgIe7tpaHm1YOpJsL6zQPNbQzRoDcYrBi77Q+gbxGPzjWfw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777464987; c=relaxed/simple; bh=0AINFMB412N4ys59nggwXI8kfKnUcgLurLm/n7HY3y4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MRsCTttFL+kopHg02asG/26dcHp4QGv45YI1n0Ba6L2OIQZqOJywGAse64axm8CJmxHlK40qM2ahiKauzcvyt4JNT+bI1Jh5oCDqQDKVKoYOeJOqhpCB1w93OBKFo43FWI5sV+RqGAhfBllS50H4LpR6TahSZVx5+N6Nl73uruk= 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=EvcDwbK8; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=MWmQRQLv; 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="EvcDwbK8"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="MWmQRQLv" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63T8q2Sx1729297 for ; Wed, 29 Apr 2026 12:16:25 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= pdgqJgNwaEnNSRtYSBvFmE51YSFb4FYx4jVfOBaK0A4=; b=EvcDwbK812CbL7se MjOpb3IXvmGsVG0ldWD3ZjxEKKtosGiFDrTUEGz1zdBQtXp0WgC3tKE9Il5aFp3y OwbGrlNNcYBNam9OEhsZFowIkxI4kJ9aPLPKI4B7wEtKHWGyQ6NhneHiAMj3cZoF N9XK+iyOKuBYRv4GeTV67IcRyTO4vCfxzjwGIwmu0y5gaTtIY6p+XXyvKpnaJbPn zB9b+NN5u54k+ZO2ZYmCLqrXjCNy+HDl8TYq7pG3se5fyuPdMn5lk5slQ0y5SaUT vP2DSPvlRDTXnCxo0JuWaNP95P4R1hm4c5G4NrXGbVC9jV0MkfX4G7w8s/aEgXfp p6R+Lg== Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4due5kry5e-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 29 Apr 2026 12:16:25 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-2da19227bc1so2681896eec.1 for ; Wed, 29 Apr 2026 05:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1777464984; x=1778069784; darn=vger.kernel.org; h=content-transfer-encoding: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; bh=pdgqJgNwaEnNSRtYSBvFmE51YSFb4FYx4jVfOBaK0A4=; b=MWmQRQLvQ8VomyMZ0e8TgBrQClPKMdnh6K9Hxhr3QcaeDQdt/vO2rekMfaMaTcmaSN KoPUv1pHBS1hGzkUUuRtui/coO7PoVv0XX29xdKicZxy0HH0wKtTJgGc1fctjuqrBr1Z BSs2iUz0yI4watysFYpCVFiHfbh0f9MMQRiyJvtPlNEg4ZZ3osBRBUhaaB0Ew8NzO+LU nsp/i5KKW0mrKWOns8P/MylfOQO4JlZFThwlhcH3J08tDXW3XyDvdD2qGQNfbGW02AED Jc4D0lrkoSLsO8UcLoWnYMwU8zl28B1rNqolTMTNrEs48I2RpOgpzw8EjtIyRE3mVCYH To/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777464984; x=1778069784; h=content-transfer-encoding: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; bh=pdgqJgNwaEnNSRtYSBvFmE51YSFb4FYx4jVfOBaK0A4=; b=F1X/QGH9uWH6N+dMtewWz8RmP73c/9qShDxjsvw/8GJngfQ/lAoY/aTkEbsqYeK7hX 6N9kkFXSM56ADZV13laukMArSBded/omAWElk/nKx+8zbqL7WMomh7nXGqOsF/LI6Spu WLHDzXLRZKsGHLmk0lypXtE8cCPFZbqZ879fl0CC7fdmfaPT9N1kspVzkzP9HC8ROQmX oB8lcAkNQOYAJYDKkdSyr0zu5hpiaIQCLUTPIx97oQEOd234Dukx3Hcdha7VX9h7WcAP rQZE/6usfLSfvZ+a5N/Rmsr88Ho45bw5ybXLFmtnY26ipyjW4s2wq7ZKuFKAePhAdYhQ jIWg== X-Forwarded-Encrypted: i=1; AFNElJ/g5Phnr7YcK3TqhO3kcMkNEu3n8pJ+lHdWMI9EGBlb7b/9TEQMwkMroSdUNUWINgyxtNxFxdxStwkJmws=@vger.kernel.org X-Gm-Message-State: AOJu0YzSkeHwj7lxvbIUa3MEdno+Ro0O6xW3CQGsmKyCDjofGEzWtgC4 0x8EG6gahfMMoPxiOPicMxVqxMRcDA/GZPyf6dGm3518SstR/cLZbTwZldpIpyjUUPGK25Fp+Wb P1NIaGoB8yrFh8YRL9AIT0mlTwGgCToKNYaT6CnN7TkIqqK67Z58vFIr7c/rpma4vUi8y6biCO5 0= X-Gm-Gg: AeBDiet4d1Nv6aEn0kcQzsd1Mna2wdJCBgKGX7KdFG8Hr8cmoHbE88CZfTkivCV1Ixa 6ewdSA/wdn0Gcd9nWftauDC0DvRgcQ7wV58Rj0lSEEzUhcf9qHqqc8j9xbCvYdgM0Us0WggdGBQ 5osOdw7GXHttgv4o3vhS1ntPJ572rbV/SQNcrH7OsJyT/kDDOE/UhhoyHRuy0IlR39NVUDgxfMU JZuJYcsli74FtA47K29Uf85Pmny9s4HwdeHliAvRyZl/OwIICr7F4cKT8UNnEU4rcd7o/47R73/ BvWkofnThqAjRR6CvGXCxtYwKKkpEcoi3YESo9LYwiVKTXTezDz8XLw6XG8hdSZFilksmdX7jbv QikUkFYNSe195zpO+UiBDqCcMk1raT3VgNhpYAgQOUTGo7ByQzMVtrEdG36gbw/8Ad2unk+STbo tua1kdhYcrj1aafQ== X-Received: by 2002:a05:693c:2c97:b0:2e7:5737:8364 with SMTP id 5a478bee46e88-2ed0a0f12a4mr3972405eec.15.1777464984210; Wed, 29 Apr 2026 05:16:24 -0700 (PDT) X-Received: by 2002:a05:693c:2c97:b0:2e7:5737:8364 with SMTP id 5a478bee46e88-2ed0a0f12a4mr3972372eec.15.1777464983599; Wed, 29 Apr 2026 05:16:23 -0700 (PDT) Received: from [10.110.45.159] (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ed1bf8e268sm1841718eec.12.2026.04.29.05.16.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Apr 2026 05:16:23 -0700 (PDT) Message-ID: <653ed773-62d9-41b4-9934-138d2ee677eb@oss.qualcomm.com> Date: Wed, 29 Apr 2026 20:16:18 +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 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 From: Linlin Zhang In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDI5MDEyNCBTYWx0ZWRfXz12w1fEF5+mo KBC3cMqGdxbSJLAz32+on3tKs+3F1d0p0PECFxkr0mO0DuzIVIJDTqYppmVcG4nYbRhSAziwz9f cOkXlcNc7ZdbNuCo64xUyB+MTAGLQOUnR6zoC7oWlXU6jg5UObS4uW9yKyvqMBxbwrOp6//X0cl x/wCaiP6OPx6OhjPK5E+zaraY6blMvKK6fXOV9qKRl6EjdgfSwNycAB8YFTm5RWFtQvj37ZAwPh PfppLRHkzeM7fP+qXfB2hvvDVq8iTzvLaBsrs3g/Db98WH+ueftJRpj1u4ctsetwa2F8KCBwtG1 uJX5tBh7AGgy6uQ1m98TlwECEN0H8sc6X/8is2pLNBWF//5k5qMx347TGMLrRLua5WMTyEFcbFi ZvS3TO6xvGO4xght6wFDfhTMMfHaHp8LIVN5lyExm6Vn79PMrv600aHrHK1updv4SUyXKm5Qyxq RwhnhQdSpM5Y2ndXSNQ== X-Proofpoint-GUID: twZbLOxc5HqWWyHCm1lx9brCbRjEbIwM X-Proofpoint-ORIG-GUID: twZbLOxc5HqWWyHCm1lx9brCbRjEbIwM X-Authority-Analysis: v=2.4 cv=CL4amxrD c=1 sm=1 tr=0 ts=69f1f699 cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=JYp8KDb2vCoCEuGobkYCKw==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=1XWaLZrsAAAA:8 a=-UBaOc0O724XT2-bv1YA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=6Ab_bkdmUrQuMsNx7PHu:22 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_05,2026-04-28_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 spamscore=0 clxscore=1015 malwarescore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2604290124 On 4/29/2026 12:20 AM, Benjamin Marzinski wrote: > On Tue, Apr 28, 2026 at 06:43:08PM +0800, Linlin Zhang wrote: >> 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). > > sector_in_target should be guaranteed to be sector_size aligned. > inlinecrypt_io_hints() sets the device logical block size to at least > ctx->sector_size, and validate_hardware_logical_block_alignment() makes > sure that the target starts on a logical block boundary. The block > layer enforces IO to be aligned with the logical block size, so > an IO that starts 7 sectors into a device with a 4096 ctx->sector_size > should be impossible. Thanks for the detailed clarification! In the next patch, I will add an explicit alignment check in ctr() to ensure that iv_offset is aligned to the configured sector size. For example: if (ctx->iv_offset & ((ctx->sector_size >> SECTOR_SHIFT) - 1)) { ti->error = "Wrong alignment of iv_offset sector"; err = -EINVAL; } Please let me know if you would like this validation to be handled differently, or if additional checks are needed. > > -Ben >