Print this page
patch as-lock-macro-simplification

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/vm_subr.c
          +++ new/usr/src/uts/common/os/vm_subr.c
↓ open down ↓ 356 lines elided ↑ open up ↑
 357  357          caddr_t         base;
 358  358          page_t          *pp, *ppp[MAX_MAPIN_PAGES];
 359  359          long            i;
 360  360          int             flags;
 361  361          size_t          size, total = *lenp;
 362  362          char            first = 1;
 363  363          faultcode_t     res;
 364  364  
 365  365          *lenp = 0;
 366  366          if (cow) {
 367      -                AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER);
      367 +                AS_LOCK_ENTER(as, RW_WRITER);
 368  368                  seg = as_findseg(as, uaddr, 0);
 369  369                  if ((seg == NULL) || ((base = seg->s_base) > uaddr) ||
 370  370                      (uaddr + total) > base + seg->s_size) {
 371      -                        AS_LOCK_EXIT(as, &as->a_lock);
      371 +                        AS_LOCK_EXIT(as);
 372  372                          return (EINVAL);
 373  373                  }
 374  374                  /*
 375  375                   * The COW scheme should work for all segment types.
 376  376                   * But to be safe, we check against segvn.
 377  377                   */
 378  378                  if (seg->s_ops != &segvn_ops) {
 379      -                        AS_LOCK_EXIT(as, &as->a_lock);
      379 +                        AS_LOCK_EXIT(as);
 380  380                          return (ENOTSUP);
 381  381                  } else if ((SEGOP_GETTYPE(seg, uaddr) & MAP_PRIVATE) == 0) {
 382      -                        AS_LOCK_EXIT(as, &as->a_lock);
      382 +                        AS_LOCK_EXIT(as);
 383  383                          return (ENOTSUP);
 384  384                  }
 385  385          }
 386  386          hat = as->a_hat;
 387  387          size = total;
 388  388  tryagain:
 389  389          /*
 390  390           * If (cow), hat_softlock will also change the usr protection to RO.
 391  391           * This is the first step toward setting up cow. Before we
 392  392           * bump up an_refcnt, we can't allow any cow-fault on this
↓ open down ↓ 84 lines elided ↑ open up ↑
 477  477                                      page_pptonum(pp), PROT_READ, flags);
 478  478                                  *cached_ppp = pp;
 479  479                          }
 480  480                          kaddr += PAGESIZE;
 481  481                  }
 482  482                  cached_ppp++;
 483  483                  app++;
 484  484                  ++i;
 485  485          }
 486  486          if (cow) {
 487      -                AS_LOCK_EXIT(as, &as->a_lock);
      487 +                AS_LOCK_EXIT(as);
 488  488          }
 489  489          if (first && res == FC_NOMAP) {
 490  490                  /*
 491  491                   * If the address is not mapped yet, we call as_fault to
 492  492                   * fault the pages in. We could've fallen back to copy and
 493  493                   * let it fault in the pages. But for a mapped file, we
 494  494                   * normally reference each page only once. For zero-copy to
 495  495                   * be of any use, we'd better fall in the page now and try
 496  496                   * again.
 497  497                   */
 498  498                  first = 0;
 499  499                  size = size << PAGESHIFT;
 500  500                  uaddr += size;
 501  501                  total -= size;
 502  502                  size = total;
 503  503                  res = as_fault(as->a_hat, as, uaddr, size, F_INVAL, S_READ);
 504  504                  if (cow)
 505      -                        AS_LOCK_ENTER(as, &as->a_lock, RW_WRITER);
      505 +                        AS_LOCK_ENTER(as, RW_WRITER);
 506  506                  goto tryagain;
 507  507          }
 508  508          switch (res) {
 509  509          case FC_NOSUPPORT:
 510  510                  return (ENOTSUP);
 511  511          case FC_PROT:   /* Pretend we don't know about it. This will be */
 512  512                          /* caught by the caller when uiomove fails. */
 513  513          case FC_NOMAP:
 514  514          case FC_OBJERR:
 515  515          default:
 516  516                  return (0);
 517  517          }
 518  518  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX