From nobody Wed Sep 21 09:30:09 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MXY6T2pbqz4cs3f; Wed, 21 Sep 2022 09:30:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MXY6T201Yz3ZZP; Wed, 21 Sep 2022 09:30:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663752609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AXbztgWXmPdJ3iTR37iCdiFPaOJ7EirAUuLwTGGrhlI=; b=KeNk/HQi6Ynab0LqEKutSPEzPy2QsSZ47Q5tL//DGZxV3vroeB8IrT4W33QfglKFRGp7QE v9A9iKJpb5ZD/x2qvGxQybBGHrhlS2DZHzbt602R5lVAaixz2kZPDjooAuPaWr5Iq9HAWL aZY5JfP5pUAL2oDL2Q8iIROfjU6N5mkgi3rWc17+YjAmwMXFSpCMqVWIoELJbaAp7hnEa2 QHVbMzBS3HmBsuC5fEne0M2FMQWAZehQfmhVSOsScDqMwk/BiasbMNjVZ5LyGFmJI1DI1f zLyQDgiLGCkOVXyWqetYrUUYybO0OQoep5YnMqf2uqQ4kGXWb2lG9CGYAQCijw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MXY6T1238z11hv; Wed, 21 Sep 2022 09:30:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28L9U94j054911; Wed, 21 Sep 2022 09:30:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28L9U9IL054908; Wed, 21 Sep 2022 09:30:09 GMT (envelope-from git) Date: Wed, 21 Sep 2022 09:30:09 GMT Message-Id: <202209210930.28L9U9IL054908@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: de7a32eaa528 - stable/13 - i386: explain the handshake between copyout_fast.s and page fault handler List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: de7a32eaa5284cb400c7cd16839fe6df0dcd0659 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663752609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AXbztgWXmPdJ3iTR37iCdiFPaOJ7EirAUuLwTGGrhlI=; b=qk9gYHatjrs5WXcrPFe9HkNjSILdKA5pkWMpqOD8AY5RhS0NBWbsBtm2w7EnfP512T5gwd XT/8CcF7RznS5VqCIoPp7vuCl5GtReuOvjwrTvVYGnMnZZKPWXQaKTNxiQo5fMPFGhzGQp ujv2bzyQo1/SqeSTxmQ8mc2jD9VmeO5BcJgqMnXdis/jH+owB3QtqhxAGw7FAtnn4RfbNQ iPdGPASL8G45gdZlhdvlZBNYNbMFLEJmfMFj3PE7mZdWuCoazXZQZAGvSQKlcEZA77KsdZ rL11+PjJ8Jy91OI0Y/B80rjyugWpTpTrwYznMNmrgI8MUgY6zE6k7wy7EGAHkA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663752609; a=rsa-sha256; cv=none; b=B/vz1sYPTByKD39xMDYWIqRhSfkTtpL6lFA33+LePAU9FOx3ehawXyxnWves4KnaaIx460 s/XGEgunpz3RDBudIO9Fc5d+vs1hX2K4jOp3CDrpOAb1NQ45uHBohX52NdtO+ZIjsVvwDA IMWYSWeVSb0vewre5aEQcpcoGj8mnRhkrE3FeHGY1x5OGGUD3WI8LYQU0sBIntu5mcRgDH pO0StL7WWHdwPSdIX1GPIk65OYCv5OE9qjWs66HCgFrpSeYPqzPP3VCIbzP+nPetIOepgU 9c6k9Ysy5uaH+gSs2jn3giCZ6jy6dJB4BXeQ6qChIC9ewOBH25T0s6IfepDeRQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=de7a32eaa5284cb400c7cd16839fe6df0dcd0659 commit de7a32eaa5284cb400c7cd16839fe6df0dcd0659 Author: Konstantin Belousov AuthorDate: 2022-09-09 20:44:48 +0000 Commit: Konstantin Belousov CommitDate: 2022-09-21 09:29:02 +0000 i386: explain the handshake between copyout_fast.s and page fault handler (cherry picked from commit 2eddd8ebf96a83fdb01d1a7e45e2d652aa05f4b8) --- sys/i386/i386/copyout_fast.s | 11 +++++++++++ sys/i386/i386/exception.s | 33 ++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/sys/i386/i386/copyout_fast.s b/sys/i386/i386/copyout_fast.s index 4391f36b18e4..2aa17a5c45c8 100644 --- a/sys/i386/i386/copyout_fast.s +++ b/sys/i386/i386/copyout_fast.s @@ -37,6 +37,17 @@ #include "assym.inc" +/* + * Fast path for copyout code. We switch to user space %cr3 and perform + * move operation between user memory and copyout buffer, located in the + * trampoline area. We must switch to trampoline stack, because both + * user and kernel buffer accesses might cause page fault. + * + * Page fault handler expects %edx to point to the onfault routine. + * Handler switches to idlePTD and calls the routine. + * The routine must restore the stack, enable interrupts, and + * return to the caller, informing it about failure. + */ .text ENTRY(copyout_fast) diff --git a/sys/i386/i386/exception.s b/sys/i386/i386/exception.s index 73d77e289e7a..010fc743dfa0 100644 --- a/sys/i386/i386/exception.s +++ b/sys/i386/i386/exception.s @@ -133,15 +133,25 @@ IDTVEC(prot) jmp irettraps IDTVEC(page) testl $PSL_VM, TF_EFLAGS-TF_ERR(%esp) - jnz 6f + jnz upf testb $SEL_RPL_MASK, TF_CS-TF_ERR(%esp) - jnz 6f + jnz upf cmpl $PMAP_TRM_MIN_ADDRESS, TF_EIP-TF_ERR(%esp) - jb 6f + jb upf + + /* + * This is a handshake between copyout_fast.s and page fault + * handler. We check for page fault occuring at the special + * places in the copyout fast path, where page fault can + * legitimately happen while accessing either user space or + * kernel pageable memory, and return control to *%edx. + * We switch to the idleptd page table from a user page table, + * if needed. + */ pushl %eax movl TF_EIP-TF_ERR+4(%esp), %eax addl $1f, %eax - call 7f + call 5f 1: cmpl $pf_x1, %eax je 2f cmpl $pf_x2, %eax @@ -162,23 +172,24 @@ IDTVEC(page) je 4f cmpl $pf_y2, %eax je 4f - jmp 5f + jmp upf_eax 2: movl $tramp_idleptd, %eax subl $3f, %eax - call 8f + call 6f 3: movl (%eax), %eax movl %eax, %cr3 4: popl %eax movl %edx, TF_EIP-TF_ERR(%esp) addl $4, %esp iret -5: popl %eax -6: pushl $T_PAGEFLT - jmp alltraps -7: subl (%esp), %eax +5: subl (%esp), %eax retl -8: addl (%esp), %eax +6: addl (%esp), %eax retl + +upf_eax:popl %eax +upf: pushl $T_PAGEFLT + jmp alltraps IDTVEC(rsvd_pti) IDTVEC(rsvd) pushl $0; TRAP(T_RESERVED)