From patchwork Wed Nov 20 23:39:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13881505 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 269F513BAF1 for ; Wed, 20 Nov 2024 23:39:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732145956; cv=none; b=QJrrvMLKI1CCeBFRoxrXSPm7G9IHXQckdPpzeavNPn1/IOGeKsqpz5fmgdUblkNp32RrVxoICOZfJWQXHQoXjYAY6rPRZ0erctzsup/GupP5SRHnpkVGSGqtgrTM16UYavI6BBjRpmr6vRO002rtzcpLriNUX3XQqIdzPDbZM6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732145956; c=relaxed/simple; bh=xwFEwAYXzGc+61bRh6SB/gdhJrx19rQhmFsTg2GHffI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HJ+N3X+9Mu0+GHx0JMXzH+1KXIEm8gpLp2NA2esqTFKwUX7TPd+vLrmePt0wcsteAs7SxfaSNKRBSUAOQwIQZ1HCpapnI3SjWjLsfuCqEIjRNhCAklzwe4PfIWcqED9JXENsHZlTL0FAcdtbogniYEcimbcNOC+Vk/jpAkq6D1A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=icj/RNg/; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="icj/RNg/" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a9e71401844so43913666b.3 for ; Wed, 20 Nov 2024 15:39:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732145953; x=1732750753; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UvLyi1ypbShfBcpFgFfb91kKYrhXAl4bDfKTMTT2lIo=; b=icj/RNg/7xFcHn+KmxpFjo6/B/oCJrxsJSvtW8wMP6EIgLvNm3h3WV77F39nJq6drS z+AGFZSGKEowMuYVUWVVfl27grsCeeY6OU2ehXw/1LBR0gJJ20H/zTREuvO+EVtyQ64n AzSXsVmuINUAmVGP+qHO57mwdL0WJNhPJEISR9JwRIqCDtVxkDpOfczL/ZhSglLkKggq 8iaOhoq+blEspkl6m6HvanMLurKY1OtzO4mlyArIQSU0qQ7Ri7wldrHtbOXOkJIq8qII zYtjW2E/gY4zlU1xmkIS8Kf7dXmHBLqWzlIny6JHhcHbzO/i8Mvl5ql4A+GkFU5m6CMC IB7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732145953; x=1732750753; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UvLyi1ypbShfBcpFgFfb91kKYrhXAl4bDfKTMTT2lIo=; b=ekXyGNVmZ+w/DD7LZ8YOwKVhQYVkXnZbEDF5Yj6mYwRvHmuKdAGQ860TOevOCE/8qc af593/BqfTKYWXz6d8wo9T3NuWEn6L/TMZU78SfdKELHR6BWLQnjgQA9idaUcv4Wtlii nRCfDASAwAsa5Eu4veEQEl0FcPMfmaFt7ZbplGNjsTe10Vg8ePAaMlJJ/d40wa8R72Sl mjgMEYJhOnoj2n7ho5F1oDfoTqwmLJnpaYz92eeiBkSGwcmD+0limejgYJQQiyRrDgsN ox4WilvVoKeKOUPTM28vTqCBJUQuZc0b0tEgcYZVgxhqlVCIL3M13ATszPxmeIpDa+Tn pL2w== X-Gm-Message-State: AOJu0YzPVsyfAGStezxgde/j23EhJopFL6+YqC/ZLtOu92+HcIfctlXS vFjxBlj/zW/Ek/kQ1zu/sqWvWUEcjzUJHewFqTZlMIy+3/jkJTAaEgET5Q== X-Google-Smtp-Source: AGHT+IHev7Ocog45eWBKkWCsWCv5GXbOa778XkAIueouq8FLaE4uHofVjf9fOTLJ+5tY+J7VMKE6zw== X-Received: by 2002:a17:907:9407:b0:a9e:8522:ba01 with SMTP id a640c23a62f3a-aa4dd723feamr470529966b.39.1732145953207; Wed, 20 Nov 2024 15:39:13 -0800 (PST) Received: from 127.0.0.1localhost ([148.252.141.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa4f418120fsm12544566b.78.2024.11.20.15.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 15:39:12 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: asml.silence@gmail.com Subject: [PATCH liburing 1/4] tests/reg-wait: test registering RO memory Date: Wed, 20 Nov 2024 23:39:48 +0000 Message-ID: <206a368e30ce838626ee998cecbe39e1d15af0f9.1731987026.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Mapping should be writable and those we can't use read only user memory, check that it fails. It also exercises one of the fail paths. Signed-off-by: Pavel Begunkov --- test/reg-wait.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/reg-wait.c b/test/reg-wait.c index b7c823a..544cd48 100644 --- a/test/reg-wait.c +++ b/test/reg-wait.c @@ -365,8 +365,22 @@ static int test_regions(void) return T_EXIT_FAIL; } rd.user_addr = (__u64)(unsigned long)buffer; - free(buffer); + + buffer = mmap(NULL, page_size, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (buffer == MAP_FAILED) { + fprintf(stderr, "mmap alloc failed\n"); + return 1; + } + + rd.user_addr = (__u64)(unsigned long)buffer; + ret = test_try_register_region(&mr, true); + if (ret != -EFAULT) { + fprintf(stderr, "test_try_register_region() RO uptr %i\n", ret); + return T_EXIT_FAIL; + } + + munmap(buffer, page_size); return 0; } From patchwork Wed Nov 20 23:39:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13881507 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88ACB1BC07B for ; Wed, 20 Nov 2024 23:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732145958; cv=none; b=jgfEKe81M1Rzpu0se2WWXW0A/mWl+AGTb7Eb73hzpQNXG2klMpw9HAPFzXt8+WNZ6tb2eJeB+gT4nx7pErcsUt7/FFBrvwNApdFg9H+13GUlEJVlf03X1QHywKO7Ez+YGqKbF3feMzYnxJwhm6RxMlK9fw6Nv+C42vM5YR43OLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732145958; c=relaxed/simple; bh=X93e4P6TrNChfhJFSS8kzIWDocqiqJKXRoBJmTVTOAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WJAaijFS7Wo1SZrMYUpavpzmhZzbte4XMFg0M+d4mwZicOnyhKkHW05GNcJR5njbLEsmuXa5g5qzVwYBwgW8an5Fh90yNSyx86w6fiZ+hK+TCWd4fNykj+WncbOMJjRdvk2j01dsnRPAJNY54dzhFAAozb0bjphT/K0WERzKAz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OW244mQq; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OW244mQq" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a9ed49edd41so53456166b.0 for ; Wed, 20 Nov 2024 15:39:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732145954; x=1732750754; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wctm1ym+mS1Y4xYRtSWfz2pW8kjA6AZFpy5byKN9nvA=; b=OW244mQqzZYvjVhyrlNZX5M6Cxj2nrsuhI8LFP1Wt2G8jopUHvoDgqFb0cP/3g/1zb s4Ju53Yi5aGBTD7ewyALEl4H9RNMCgX15HUnvveE9T3C7oOIpQszpcBKBcAiBtHKlTAx PGlRLSPYzNqcPByj3qGcLtbU+bvKFb6Eb7UsV9VDShEUNN7/oAH/xpnJ869ZXcyNrRLE 8yqYVfOl/xXsB8nFLN0OqWrt2D/awPPlSKzZ4M043K33C/a5YslaGdXSwRSBe0TCFQVp Qbo4YX9vhmYauWN+qOENFC1R8/67Lgd5pE7uxnBbGx2ziCpE0LV5QJaP2WcNkM18y+Lm Mclw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732145954; x=1732750754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wctm1ym+mS1Y4xYRtSWfz2pW8kjA6AZFpy5byKN9nvA=; b=msQEZIApbzz+lCnvfyJAXwBQvdwDcEJV+Va4+kLUOSmXL55QoMunaOLQM0AsimlwbV 0xKCQyJJCZVLIoLE48sdCsjdFYbteM5Ee4gBaA+2YRB5z3ix6PdAHLqUF3TFGTiOD5IK zWdvxhWXqjg28Hd6CcWwbC3TG1Dl/kknVMuhfgp4iZpDW38zu9daUzQN7RNMoZFRoO2Q qls5knQXro5p//wxn9VQQ0yX5j6Mg3swQ25EyaCaFJap4weuIlQ5+HcvSGxzwomeR1TO t++tX3Q+AQAXzJrCyQ8QBVtWviEGUtI8QIY9T8dhgUeFPe5ZGO583Dz5bvtBpFso/rvc iVdQ== X-Gm-Message-State: AOJu0YwAIbMSNtVk+yleJ1c6S7jbkG/APIk/mOrZIMTANh1PXI4wR4cP QQ/flc7tjTLLzmjhBD1qb/LrFidlICVs8jTLJ2LkagPCvKAUZd2KfUnlMA== X-Gm-Gg: ASbGncuqrOawWwcS4IIKJAS0rOdq4S/xoN/eoKJiwSDOAwG2qvknqOEDzwqCJg4M8q+ 9pZGLUoBUG5xD3YzbChVgfi62RdYj5YR0rELPgtNLDKPrL2OvtEF0bzbddm/KSmFO2pHdeKTnlA AAvjf1UcrUcKAZx4QQ5hkU81OE2Yxik2AvdxFkJ3Z0yNMi6D3Ag15UhgoXx3HcqThhuIJ9RPg/F +DKw9hvo3n8N3wFdaRWiuLrRi00sVWsHh0gGcLI7BkCgI5xoxq6OzWhtVdqg6J2 X-Google-Smtp-Source: AGHT+IF6ojHr7YeOYwFHqfyXJvgsynhEM7aND1VU2+A7a8VLDld5B4aEFjRBhTFhpVe3qQFzbzoT2A== X-Received: by 2002:a17:907:3f99:b0:a9e:c947:8c5e with SMTP id a640c23a62f3a-aa4dd749167mr491479666b.57.1732145954222; Wed, 20 Nov 2024 15:39:14 -0800 (PST) Received: from 127.0.0.1localhost ([148.252.141.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa4f418120fsm12544566b.78.2024.11.20.15.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 15:39:13 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: asml.silence@gmail.com Subject: [PATCH liburing 2/4] test/reg-wait: basic test + probing of kernel regions Date: Wed, 20 Nov 2024 23:39:49 +0000 Message-ID: <8a525a846002b2a899addbae52f922d9034b4257.1731987026.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Pavel Begunkov --- test/reg-wait.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/reg-wait.c b/test/reg-wait.c index 544cd48..9b18ab1 100644 --- a/test/reg-wait.c +++ b/test/reg-wait.c @@ -23,6 +23,8 @@ static const struct io_uring_reg_wait brief_wait = { .ts.tv_nsec = 1000, }; +static bool has_kernel_regions; + static int test_wait_reg_offset(struct io_uring *ring, unsigned wait_nr, unsigned long offset) { @@ -380,6 +382,27 @@ static int test_regions(void) return T_EXIT_FAIL; } + rd.flags = 0; + rd.user_addr = 0; + ret = test_try_register_region(&mr, true); + if (ret == -EINVAL) { + has_kernel_regions = false; + goto out; + } + if (ret) { + fprintf(stderr, "test_try_register_region() failed kernel alloc %i\n", ret); + return T_EXIT_FAIL; + } + + has_kernel_regions = true; + rd.flags = 0; + rd.user_addr = (__u64)(unsigned long)buffer; + ret = test_try_register_region(&mr, true); + if (!ret) { + fprintf(stderr, "test_try_register_region() failed uptr w kernel alloc %i\n", ret); + return T_EXIT_FAIL; + } +out: munmap(buffer, page_size); return 0; } From patchwork Wed Nov 20 23:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13881508 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A8031C304F for ; Wed, 20 Nov 2024 23:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732145960; cv=none; b=mG2uHFyWih4Pt5tcApH0APaXaRiJAqlkm7xbsOJWlVxzowkgQeMMBsr9Xehr/HKV3+wdMTX20UI0e34XAHrzVtN8/mY7z+KOECnqHKnGB9rRoHpcfnxXM/Y16jv99h53HE4y6Nnf/3ieRwvd3eCx7NGSAwkAOmRNjIhACUeBU/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732145960; c=relaxed/simple; bh=L2B3JsoWYtc7K/z17sFcQCnlYHwaq7AEdp+VwXjhI0o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r8iLtCp4cslirb18beHIIRrxa6Q8qN8qfFKL/WwXICrGsZkpfe22oBNMz14uDs4nOBmDjQoyv5Fxmw84RxkTaZovhLl4EOlPDl8V2eQFHY8PleQrkf/hGpv90Vo5ta/2dbQXAAOpo4LxWWKbP9cf9DSjp+fcgBdvjC5In5qEomM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dixf142m; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dixf142m" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-53dcb6f68b1so116927e87.3 for ; Wed, 20 Nov 2024 15:39:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732145956; x=1732750756; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+eqVQFABLZJJv+bkoApoYkStReOdoYQCm+mvVfO46wk=; b=Dixf142mMt+I/063sOg8gZ61QGQwx8JF5eiQvs5L2MLeXL4Jc5zdFWRl6e1Nqv5hVk anhcxW533RwhU8QoMwsZWtph2je02P92NHfm7q16eCQp0dRMSgM0w242ZBVTyDnSDmvh kx8KusUDhhYzpfn1yaxZ7G8D+9lJQIKs3lO4f6m/Ya7s27g/a88PUX0G36b3sQ6bVltL SJzj73SpiH5CRkSb6UPq+WcWFDT8Ofxe8yZotw/DiMz/uf0wzs7huf5DpT92E8HBzzfS DDhfNLjeW/mbEZDx5capOe7XINa+sJTyapJdOQG2/brTeTowEj/F1GsFVR0qdgp8Lkby 3A3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732145956; x=1732750756; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+eqVQFABLZJJv+bkoApoYkStReOdoYQCm+mvVfO46wk=; b=lFIm4viGnR8iYzGjwd0wxrG3zlrOcdN497PcWMjubzcR1iA5OrfkmbLs+9swFtGeod p/IyVeP5QkEGnjKN42bGCWArCaYxd9Ok92b/VQ9MPaxlEcquJbq81qGZ35hgOohxzRx/ mfnV3b4Uj3NPa16WmjJ9zfslKVK233YhXD2j7jNmY/4/n+wxRQZdU5YRGRi1LVOQEXGS hpAZ54zjoKWxhV+9XH9Rlg6/bo7MG0G50xg3dRxpJY++4gZRVgG4I2ZMQTV3d4DdBHp1 nYjwtlUWDuICcAuioD0lk463a+rkA39QaLCNgiI8HmdiSx2hY/ePPdn3MPxm32CYz8fD qCBQ== X-Gm-Message-State: AOJu0YzVNUXpw6H43cghqC8+ygXS8W3yj9+kHiU4bRflxI6kGl0TwBw+ A0D7w37Ws0T92eTgWv95gphPWEwXRgH/2fJ67GZE7U5b2iq8nHI7fg/owA== X-Gm-Gg: ASbGncvcl1G27vrJJVCkVx2yMlcJYLEo8YgLGXcoLu+5kIrF83uqrPIs7TxUZO0DpTU /Q39HFNZIOhz3N360iM/6+QnDbm6XCPh5knq6hvIeOFexaz1h3yhaVHkMjxKlT8Kbg2BG2e+7nR GAzdXkXm3s2XanAfvs0F6ktH7UKHMarqNPCrjXcyqWVRMt3PmOxu+A1YSZDTw2fHuKCYiuLouVL 5RaLB+s7T3rBxZs8/x/SUZRjTUvM4CcBsbfJjWIpR8NALGOlhPy+7NnvzBd1Qyq X-Google-Smtp-Source: AGHT+IHR60F02KPCqEE0F/4KiXNLNafuOOCQdC0QwkwufuV7ElgmnehKSFb5fnfhRZJQPaZAds/6+A== X-Received: by 2002:a05:6512:3a87:b0:539:f93d:eb3d with SMTP id 2adb3069b0e04-53dc1369cbfmr2070679e87.46.1732145955514; Wed, 20 Nov 2024 15:39:15 -0800 (PST) Received: from 127.0.0.1localhost ([148.252.141.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa4f418120fsm12544566b.78.2024.11.20.15.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 15:39:15 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: asml.silence@gmail.com Subject: [PATCH liburing 3/4] test/reg-wait: add allocation abstraction Date: Wed, 20 Nov 2024 23:39:50 +0000 Message-ID: <75e1f917fa8cec832065e4edc08e2c04644545cf.1731987026.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Pavel Begunkov --- test/reg-wait.c | 82 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/test/reg-wait.c b/test/reg-wait.c index 9b18ab1..d59e51b 100644 --- a/test/reg-wait.c +++ b/test/reg-wait.c @@ -67,12 +67,6 @@ err: return ret; } -static int init_ring_with_region(struct io_uring *ring, unsigned ring_flags, - struct io_uring_mem_region_reg *pr) -{ - return __init_ring_with_region(ring, ring_flags, pr, true); -} - static int page_size; static struct io_uring_reg_wait *reg; @@ -407,15 +401,49 @@ out: return 0; } -static void *alloc_region_buffer(size_t size, bool huge) +struct t_region { + void *ptr; + bool user_mem; + size_t size; +}; + +static void t_region_free(struct t_region *r) { + if (r->ptr) + munmap(r->ptr, r->size); +} + +static int t_region_create_user(struct t_region *r, + struct io_uring *ring, + bool huge) +{ + struct io_uring_region_desc rd = {}; + struct io_uring_mem_region_reg mr = {}; int flags = MAP_PRIVATE | MAP_ANONYMOUS; void *p; + int ret; if (huge) flags |= MAP_HUGETLB | MAP_HUGE_2MB; - p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); - return p == MAP_FAILED ? NULL : p; + + p = mmap(NULL, r->size, PROT_READ | PROT_WRITE, flags, -1, 0); + if (p == MAP_FAILED) + return -ENOMEM; + + mr.region_uptr = (__u64)(unsigned long)&rd; + mr.flags = IORING_MEM_REGION_REG_WAIT_ARG; + rd.user_addr = (__u64)(unsigned long)p; + rd.flags = IORING_MEM_REGION_TYPE_USER; + rd.size = r->size; + + ret = io_uring_register_region(ring, &mr); + if (ret) { + munmap(p, r->size); + return ret; + } + r->ptr = p; + r->user_mem = true; + return 0; } static int test_region_buffer_types(void) @@ -423,40 +451,42 @@ static int test_region_buffer_types(void) const size_t huge_size = 1024 * 1024 * 2; const size_t map_sizes[] = { page_size, page_size * 2, page_size * 16, huge_size, 2 * huge_size}; - struct io_uring_region_desc rd = {}; - struct io_uring_mem_region_reg mr = {}; struct io_uring ring; int sz_idx, ret; - mr.region_uptr = (__u64)(unsigned long)&rd; - mr.flags = IORING_MEM_REGION_REG_WAIT_ARG; - for (sz_idx = 0; sz_idx < ARRAY_SIZE(map_sizes); sz_idx++) { size_t size = map_sizes[sz_idx]; - void *buffer; + struct t_region r = { .size = size, }; - buffer = alloc_region_buffer(size, size >= huge_size); - if (!buffer) - continue; - - rd.user_addr = (__u64)(unsigned long)buffer; - rd.size = size; - rd.flags = IORING_MEM_REGION_TYPE_USER; + ret = io_uring_queue_init(8, &ring, IORING_SETUP_R_DISABLED); + if (ret) { + fprintf(stderr, "ring setup failed: %d\n", ret); + return ret; + } - ret = init_ring_with_region(&ring, 0, &mr); + ret = t_region_create_user(&r, &ring, size >= huge_size); if (ret) { - fprintf(stderr, "init ring failed %i\n", ret); + io_uring_queue_exit(&ring); + if (ret == -ENOMEM || ret == -EINVAL) + continue; + fprintf(stderr, "t_region_create_user failed\n"); return 1; } - ret = test_offsets(&ring, buffer, size, false); + ret = io_uring_enable_rings(&ring); + if (ret) { + fprintf(stderr, "io_uring_enable_rings failure %i\n", ret); + return ret; + } + + ret = test_offsets(&ring, r.ptr, size, false); if (ret) { fprintf(stderr, "test_offsets failed, size %lu\n", (unsigned long)size); return 1; } - munmap(buffer, size); + t_region_free(&r); io_uring_queue_exit(&ring); } From patchwork Wed Nov 20 23:39:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13881509 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E68B71C3F0E for ; Wed, 20 Nov 2024 23:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732145960; cv=none; b=EQ6H9bO5UKi6nZzRgUNTIRYlR3+tJSlJYfq7HTv/WbK7UE75/jGuM+Q6umKJsHtHY5W5FiyNNpFXPaznuaRAkaAlHulnKl5Tt7NDniyLvpnVkPLIO8G/0POaYzUv5Hm4IuLKhui0e8oL2usgkpdMF5wHswfnSa01TarOpjQMG4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732145960; c=relaxed/simple; bh=CSRCw925h0xPkBhV0+xncLyeFiq36jeusAlSTLuKXVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=prFs4frBaJ0SJft306cR9zDo6C9zLuU0ur4RgxG5JFvnWkvZDinozkSqXAmZXBVkkLBjnHBQDhwYoBbXpxEpRHRF3H1lZB5Mdt6dXKhCy3y6UCcbXlV4+aoOnO27QOiPyW2UvDu1fbMlkDCnwUGe2hBpEY8+Fcc5y9FJ5XVkGg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QPxf0yYJ; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QPxf0yYJ" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a9e8522c10bso45717866b.1 for ; Wed, 20 Nov 2024 15:39:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732145957; x=1732750757; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FD7qJ37j4F2SjsPExi3zhKBut3tTRkbQuozGRoZgzps=; b=QPxf0yYJg2LL6peaNhlkWRqVTRdUaEYj5F2I6GwTrer9BYR9/2/MQY5dcMAHaNEEtg zNNBkVNjzVf9spoAzOQ0u9JlH8GNt8EVwZnkCIrrXPCYHPg9chl3fGwjqV7R6SlZWFtW mXKbKafA47pcqBblaQ7RhTjUHgwdr2XriUHGlTMXVV/Np8iOYuhSjNjtZs8VZsMgoP4x RGQAj7uk2yXGqqpAscaDyAJMr29w/+lt7HcbqnY2UvDOapaU4+eNfryITRIxKKLcitzk sKqP9BphumSpyXqrV4yyVBvKnmUdOnDovENY3YAUiPhFQ+S/sljHD3L7YEtCVqDB3TwM PetA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732145957; x=1732750757; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FD7qJ37j4F2SjsPExi3zhKBut3tTRkbQuozGRoZgzps=; b=rEjAJfpMiretiKsefiVKOTWPfCjOP3STTZ37J/QqYVFhBCa8MbV/jASzIqqv9iXBYy 81jfVShqV9BwZraw0mOT+Mm2tSAgGNRF+9pPZY4W+prX8nHDRMgpUIU6wm4zZyRI8+hv OxEzlnW65te2vOVn7GKu42eJGpxTAxkHF8rEK6SYyeXKjZ6EhjDxs686WPO+08D6PlFY XomncGDhxeV4WeavaieMhRSGNuheDlixTlFp7BSi2G/KBhhk1j9GvsadtSUIWRGyk2u0 K4N3JQPcgWuwg/RttHWLBYnXpptwEesm1c3bpeBwbXLzW+27VGCSOte6pmNg+iCrUG13 Lhbg== X-Gm-Message-State: AOJu0YzGIEvFp2kWQXLmP2p0t3IiDtNwaKUEzEV20RVNYdMjjF5Eka22 sgNwObL6tQeFxuvi8IWaZSwTLyDorU/svYwca8MJL+EtMeONt2c3sFeRyw== X-Google-Smtp-Source: AGHT+IGHyQoObkjZgreYtxVX6YdcezFTA7YqQk8N5lOaFIyTceuSSqYxhq1o/snpvmLT24WujReLCw== X-Received: by 2002:a17:907:7b86:b0:a99:f5d8:726 with SMTP id a640c23a62f3a-aa4efdd0c3bmr87271366b.23.1732145956974; Wed, 20 Nov 2024 15:39:16 -0800 (PST) Received: from 127.0.0.1localhost ([148.252.141.165]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa4f418120fsm12544566b.78.2024.11.20.15.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 15:39:15 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: asml.silence@gmail.com Subject: [PATCH liburing 4/4] test/reg-wait: test kernel allocated regions Date: Wed, 20 Nov 2024 23:39:51 +0000 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Pavel Begunkov --- test/reg-wait.c | 68 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/test/reg-wait.c b/test/reg-wait.c index d59e51b..299fbf1 100644 --- a/test/reg-wait.c +++ b/test/reg-wait.c @@ -413,6 +413,31 @@ static void t_region_free(struct t_region *r) munmap(r->ptr, r->size); } +static int t_region_create_kernel(struct t_region *r, + struct io_uring *ring) +{ + struct io_uring_region_desc rd = { .size = r->size, }; + struct io_uring_mem_region_reg mr = { + .region_uptr = (__u64)(unsigned long)&rd, + .flags = IORING_MEM_REGION_REG_WAIT_ARG, + }; + void *p; + int ret; + + ret = io_uring_register_region(ring, &mr); + if (ret) + return ret; + + p = mmap(NULL, r->size, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_POPULATE, ring->ring_fd, rd.mmap_offset); + if (p == MAP_FAILED) + return -EFAULT; + + r->ptr = p; + r->user_mem = false; + return 0; +} + static int t_region_create_user(struct t_region *r, struct io_uring *ring, bool huge) @@ -446,17 +471,36 @@ static int t_region_create_user(struct t_region *r, return 0; } +struct test_param { + size_t size; + bool huge_page; + bool kern_buf; +}; + static int test_region_buffer_types(void) { const size_t huge_size = 1024 * 1024 * 2; - const size_t map_sizes[] = { page_size, page_size * 2, page_size * 16, - huge_size, 2 * huge_size}; + struct test_param params[] = { + { .size = page_size }, + /* forcing vmap */ + { .size = page_size * 2 }, + { .size = page_size * 16 }, + /* huge page w/o vmap */ + { .size = huge_size, .huge_page = true }, + /* huge page w/ vmap */ + { .size = huge_size * 2, .huge_page = true }, + { .size = page_size, .kern_buf = true }, + /* likely to be a compound page */ + { .size = page_size * 2, .kern_buf = true }, + { .size = page_size * 8, .kern_buf = true }, + /* kernel allocation + vmap */ + { .size = page_size * 512, .kern_buf = true }, + }; struct io_uring ring; - int sz_idx, ret; + int i, ret; - for (sz_idx = 0; sz_idx < ARRAY_SIZE(map_sizes); sz_idx++) { - size_t size = map_sizes[sz_idx]; - struct t_region r = { .size = size, }; + for (i = 0; i < ARRAY_SIZE(params); i++) { + struct t_region r = { .size = params[i].size, }; ret = io_uring_queue_init(8, &ring, IORING_SETUP_R_DISABLED); if (ret) { @@ -464,12 +508,15 @@ static int test_region_buffer_types(void) return ret; } - ret = t_region_create_user(&r, &ring, size >= huge_size); + if (params[i].kern_buf) + ret = t_region_create_kernel(&r, &ring); + else + ret = t_region_create_user(&r, &ring, params[i].huge_page); if (ret) { io_uring_queue_exit(&ring); if (ret == -ENOMEM || ret == -EINVAL) continue; - fprintf(stderr, "t_region_create_user failed\n"); + fprintf(stderr, "t_region_create_user failed, idx %i\n", i); return 1; } @@ -479,10 +526,9 @@ static int test_region_buffer_types(void) return ret; } - ret = test_offsets(&ring, r.ptr, size, false); + ret = test_offsets(&ring, r.ptr, r.size, false); if (ret) { - fprintf(stderr, "test_offsets failed, size %lu\n", - (unsigned long)size); + fprintf(stderr, "test_offsets failed, idx %i\n", i); return 1; }